【发布时间】:2011-04-29 21:32:33
【问题描述】:
我是 Iphone 开发新手,任何人都可以帮助我获取示例代码,以使用 iphone 通过 SMTP 发送带有附件的邮件。
我已经尝试过以下 URL 中的示例代码
http://code.google.com/p/skpsmtpmessage/
谢谢
【问题讨论】:
我是 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 对象都可以工作,但只要您初始化它你正确设置了你的 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];
【讨论】: