Last active
March 4, 2021 00:10
-
-
Save glennposadas/346fcfcb0b06d9a97d0e668002c9e51f to your computer and use it in GitHub Desktop.
Sample full code of sending an email using MailCore2 in Objective-C
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
- (IBAction)sendEmail:(id)sender { | |
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init]; | |
MCOAddress *address = [MCOAddress addressWithDisplayName:@"Uplant Support" mailbox:@"noreply.uplant@gmail.com"]; | |
NSArray *to = [NSArray arrayWithObject:[MCOAddress addressWithDisplayName:@"Glenn Posadas" mailbox:@"admin@glennvon.com"]]; | |
[[builder header] setFrom:address]; | |
[[builder header] setTo:to]; | |
[[builder header] setSubject:@"This is a nice subject"]; | |
[builder setHTMLBody:@"The motherloving body."]; | |
NSData * data = [builder data]; | |
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init]; | |
[smtpSession setHostname:@"smtp.gmail.com"]; | |
[smtpSession setUsername:@"noreply.uplant@gmail.com"]; | |
[smtpSession setPassword:@"----"]; | |
[smtpSession setPort:465]; | |
[smtpSession setConnectionType:MCOConnectionTypeTLS]; | |
MCOSMTPSendOperation *smtpSender = [smtpSession sendOperationWithData: data]; | |
[smtpSender start:^(NSError * _Nullable error) { | |
NSLog(@"Error: %@", error.localizedDescription); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment