任何人都知道在 iphone 应用程序中使用的 Objective-C smtp 库。
我使用skpsmtpmessagehttp://code.google.com/p/skpsmtpmessage/ http://code.google.com/p/skpsmtpmessage/但当发送邮件到 gmail 时,它会将邮件正文作为附件发送。
thanks.
尝试使用https://github.com/MailCore/mailcore2 https://github.com/MailCore/mailcore2。它是异步的,支持大多数邮件协议。
看一下发送邮件的例子:
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = @"[email protected] /cdn-cgi/l/email-protection";
smtpSession.password = @"password";
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType = MCOConnectionTypeTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
mailbox:@"[email protected] /cdn-cgi/l/email-protection"];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil
mailbox:@"[email protected] /cdn-cgi/l/email-protection"];
[[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!");
}
}];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)