Sendung von Mailcore2 Plain Emails in Swift

Ich habe kürzlich MailCore2 in mein Objective-C-Projekt aufgenommen und es hat perfekt funktioniert. Jetzt bin ich dabei, den Code innerhalb der App auf Swift umzustellen. Ich habe die MailCore2-API erfolgreich in mein SWIFT-Projekt importiert, sehe jedoch keine Dokumentation (Google-Suche, libmailcore.com, github), wie der folgende Objective-C-Code in SWIFT-Code umgewandelt werden kann:

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 mit dieser API erfolgreich eine E-Mail in Swift sendet? Vielen Dank im Voraus an alle, die antworten.

Antworten auf die Frage(8)

Ihre Antwort auf die Frage