iphone smtp client library

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:17:07

问题


any one knows an objective-c smtp library for use in iphone app.

I use skpsmtpmessage http://code.google.com/p/skpsmtpmessage/ but it sends message body as attachment when send mail to gmail.

thanks.


回答1:


Try to use https://github.com/MailCore/mailcore2. It is Asynchronous and support most of mail protocol.

Look at the Sending Mail Example:

 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!");
   }
}];



回答2:


I use the same library in one of my iOS app. I successfully send the message text, attachments and all. Here is the portion of my code for the message text body:

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];


来源:https://stackoverflow.com/questions/3440730/iphone-smtp-client-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!