Skip to content

Instantly share code, notes, and snippets.

@mronge
Last active April 27, 2022 07:24
Show Gist options
  • Save mronge/5694886 to your computer and use it in GitHub Desktop.
Save mronge/5694886 to your computer and use it in GitHub Desktop.
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!");
}
}];
@dinhvh
Copy link

dinhvh commented Jun 3, 2013

smtpSession.authType = (MCOAuthTypeSASLPlain | MCOAuthTypeSASLLogin);
It's misleading, authType is not supposed to be a bit mask.
Could you remove it?

@ocrickard
Copy link

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