我是Iphone开发的新手,任何人都可以通过SMTP使用iphone通过SMTP发送邮件来获取示例代码。
我已尝试过以下网址中的示例代码
http://code.google.com/p/skpsmtpmessage/
谢谢
答案 0 :(得分:2)
以下是使用邮件附加文件的示例代码。
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];
答案 1 :(得分:0)
以下是我们如何使用我们的邮件消息发送附件(以下附加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];