Created
January 22, 2015 17:17
-
-
Save ksksue/7321100b94dee083e1f5 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
#include <MailCore/MailCore.h> | |
... | |
-(void) sendEmail:(NSString *) message | |
{ | |
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init]; | |
smtpSession.hostname = @"smtp.gmail.com"; // SMTPサーバのアドレス | |
smtpSession.port = 465; | |
smtpSession.username = @"moemoe"; // SMTPサーバのユーザ名 | |
smtpSession.password = @"tsun dere"; // SMTPサーバのパスワード | |
smtpSession.authType = MCOAuthTypeSASLPlain; | |
smtpSession.connectionType = MCOConnectionTypeTLS; | |
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init]; | |
MCOAddress *from = [MCOAddress addressWithDisplayName:nil | |
mailbox:@"from@mail.com"]; // 送信元メールアドレス | |
MCOAddress *to = [MCOAddress addressWithDisplayName:nil | |
mailbox:@"to@mail.com"]; // 送信先メールアドレス | |
[[builder header] setFrom:from]; | |
[[builder header] setTo:@[to]]; | |
[[builder header] setSubject:@"ここにサブジェクト"]; | |
[builder setHTMLBody: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!"); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment