![](/img/trans.png)
[英]write own mail client to send Mail using SMTP/POP3 server on iphone
[英]How to send the mail with attachment through SMTP using iphone
我是 iPhone 开发的新手,任何人都可以帮助我获取示例代码,以使用 iphone 通过 SMTP 发送带有附件的邮件。
我已经尝试了以下 URL 的示例代码
http://code.google.com/p/skpsmtpmessage/
谢谢
下面是使用邮件附加文件的示例代码。
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];
以下是我们通过邮件发送附件的方式(以下附加一个 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.