Senden Mailcore2 Plain-E-Mails in Swift

Ich habe vor kurzem MailCore2 in meine Objective-C-Projekt, und es hat perfekt funktioniert. Nun, ich bin in den Prozess der Umstellung der code innerhalb der app zu Swift. Ich habe erfolgreich importiert MailCore2 API in meine swift-Projekt, aber ich sehe keine Dokumentation (Google-Suche, libmailcore.com, github) auf, wie Sie die folgenden arbeiten Objective-C code in Swift-Code:

MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = @"[email protected]";
smtpSession.password = @"password";
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType = MCOConnectionTypeTLS;

MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
                                              mailbox:@"[email protected]"];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil 
                                            mailbox:@"[email protected]"];
[[builder header] setFrom:from];
[[builder header] setTo:@[to]];
[[builder header] setSubject:@"My message"];
[builder setHTMLBody:@"This is a test message!"];
NSData * rfc822Data = [builder data];

MCOSMTPSendOperation *sendOperation = 
   [smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
    if(error) {
        NSLog(@"Error sending email: %@", error);
    } else {
        NSLog(@"Successfully sent email!");
    }
}];

Weiß jemand, wie man erfolgreich eine E-Mail senden an Swift, die diese API nutzen? Vielen Dank im Voraus an alle, die Antworten.

InformationsquelleAutor iProgramIt | 2015-07-17
Schreibe einen Kommentar