任何人都知道在iphone app中使用的objective-c smtp库。
我使用skpsmtpmessage http://code.google.com/p/skpsmtpmessage/但是在向gmail发送邮件时它会将邮件正文作为附件发送。
感谢。
答案 0 :(得分:4)
尝试使用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!");
}
}];
答案 1 :(得分:0)
我在一个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];