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

时间:2021-07-18 14:32:51

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

谢谢

2 个解决方案

#1


2  

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

#2


0  

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并假设文件名已经被设置到bundle中的其他位置,但是实际上任何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];

#1


2  

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

#2


0  

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并假设文件名已经被设置到bundle中的其他位置,但是实际上任何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];