Last active
April 27, 2022 07:24
-
-
Save mronge/5694886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init]; | |
smtpSession.hostname = @"smtp.gmail.com"; | |
smtpSession.port = 465; | |
smtpSession.username = @"matt@gmail.com"; | |
smtpSession.password = @"password"; | |
smtpSession.authType = MCOAuthTypeSASLPlain; | |
smtpSession.connectionType = MCOConnectionTypeTLS; | |
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init]; | |
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R" | |
mailbox:@"matt@gmail.com"]; | |
MCOAddress *to = [MCOAddress addressWithDisplayName:nil | |
mailbox:@"hoa@gmail.com"]; | |
[[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!"); | |
} | |
}]; |
Yeah, my bad. I was confused about authType...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
smtpSession.authType = (MCOAuthTypeSASLPlain | MCOAuthTypeSASLLogin);
It's misleading, authType is not supposed to be a bit mask.
Could you remove it?