简体   繁体   English

如何使用 iphone 通过 SMTP 发送带有附件的邮件

[英]How to send the mail with attachment through SMTP using iphone

Im new to Iphone develoment can any one helpme in getting sample code in send the mail with attachment through SMTP using iphone.我是 iPhone 开发的新手,任何人都可以帮助我获取示例代码,以使用 iphone 通过 SMTP 发送带有附件的邮件。

i have tried the sample code from this following URL我已经尝试了以下 URL 的示例代码

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

Thanks谢谢

Below is the sample code to attach file with mail.下面是使用邮件附加文件的示例代码。

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

Here is how we send attachments with our mail messages (the following attaches a jpeg and assumes fileName has been set elsewhere to a location within your bundle, but really any NSData object will work however you initilize it as long as you set your mimeType correctly) :以下是我们通过邮件发送附件的方式(以下附加一个 jpeg 并假设 fileName 已在您的捆绑包中的其他位置设置,但实际上任何 NSData object 都可以使用,但是只要您正确设置 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM