【问题标题】:How to send the mail with attachment through SMTP using iphone如何使用 iphone 通过 SMTP 发送带有附件的邮件
【发布时间】:2011-04-29 21:32:33
【问题描述】:

我是 Iphone 开发新手,任何人都可以帮助我获取示例代码,以使用 iphone 通过 SMTP 发送带有附件的邮件。

我已经尝试过以下 URL 中的示例代码

http://code.google.com/p/skpsmtpmessage/

谢谢

【问题讨论】:

    标签: iphone ipad email smtp


    【解决方案1】:

    下面是使用邮件附加文件的示例代码。

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    
    [picker setSubject:@"Hello"];
    
    
    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 
    
    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];  
    [picker setBccRecipients:bccRecipients];
    
    // Attach an image to the email
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"myFile"];
    
    // Fill out the email body text
    NSString *emailBody = @"Message body : my first email sending ";
    [picker setMessageBody:emailBody isHTML:NO];
    
    [self presentModalViewController:picker animated:YES];
    [picker release];
    

    【讨论】:

      【解决方案2】:

      这里是我们如何通过邮件消息发送附件(以下附加一个 jpeg 并假设 fileName 已在其他位置设置到您的包中的某个位置,但实际上任何 NSData 对象都可以工作,但只要您初始化它你正确设置了你的 mimeType):

      MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
      mailViewController.mailComposeDelegate = self;
      [mailViewController setMessageBody:@"Some Message" isHTML:YES];
      [mailViewController setSubject:@"My Subject"];
      [mailViewController addAttachmentData:[NSData dataWithContentsOfFile:fileName] mimeType:@"image/jpeg" fileName:@"PrettyPicture.jpg"];
      [self presentModalViewController:mailViewController animated:YES];
      [mailViewController release];
      

      【讨论】:

        猜你喜欢
        • 2012-05-24
        • 1970-01-01
        • 1970-01-01
        • 2011-06-08
        • 2013-10-31
        • 2020-09-12
        • 1970-01-01
        • 2014-03-05
        • 1970-01-01
        相关资源
        最近更新 更多