任何人都知道用于 iphone 应用程序的 Objective-C smtp 库。
我使用 skpsmtpmessage http://code.google.com/p/skpsmtpmessage/ 但它在向 gmail 发送邮件时将邮件正文作为附件发送。
谢谢。
任何人都知道用于 iphone 应用程序的 Objective-C smtp 库。
我使用 skpsmtpmessage http://code.google.com/p/skpsmtpmessage/ 但它在向 gmail 发送邮件时将邮件正文作为附件发送。
谢谢。
尝试使用https://github.com/MailCore/mailcore2。它是异步的,支持大多数邮件协议。
查看发送邮件示例:
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!");
}
}];
我在我的一个 iOS 应用程序中使用相同的库。我成功发送了消息文本、附件和所有内容。这是消息文本正文的代码部分:
NSString *messageBody = @"xxxxxx";
// Now creating plain text email message
NSDictionary *plainMsg = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, messageBody,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
emailMessage.parts = [NSArray arrayWithObjects:plainMsg,nil];
[emailMessage send];