【问题标题】:iphone smtp client libraryiphone smtp 客户端库
【发布时间】:2011-03-27 07:48:51
【问题描述】:

任何人都知道用于 iphone 应用程序的 Objective-c smtp 库。

我使用 skpsmtpmessage http://code.google.com/p/skpsmtpmessage/,但它在向 gmail 发送邮件时将邮件正文作为附件发送。

谢谢。

【问题讨论】:

标签: iphone objective-c smtp smtpclient


【解决方案1】:

尝试使用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!");
   }
}];

【讨论】:

    【解决方案2】:

    我在我的一个 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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      相关资源
      最近更新 更多