views:

458

answers:

5

Hi, I have used the MFMailComposeViewController to send the generated report(csv).

Now mail is sent to To:email id, & but when i checked the mails i did received the mail but attachment was not there.

Then I also tried MailComposer example :

https://developer.apple.com/iphone/library/samplecode/MailComposer/index.html

in which the png image is attached to mail demo. I also sent mail using that app, But same result image attachment is not delivered.

Help, to find what's the problem? Thanks in advance.

Here is code in that app :

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello from California!"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

[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:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];
A: 

If your code looks okay I'll suspect that that myData didn't get loaded with data is nil. Put in an NSLog([myData description]) or use the debugger to check that myData is not nil.

Harry
Thanks dude...i checked the mydata and its not nil..!!!!but still i cant find attachment.
Nic
A: 

I'm out of ideas. If I was stuck in this situation I would create a stand alone project with the example code you provided and see if I could get it working. Usually in these situations the code you are focusing on is probably correct and error is coming from somewhere else.

Also:

  • Check to see if the path variable is nil because that will cause the attachment to not appear.
  • Make sure there is a icon in message body the mail compose view. When you successfully add an attachment you should see the icon representation in the view.
  • And you probably want set your fileName to rainy.png, i.e. [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy.png"].

Good luck.

Harry
thanks .. i checked the path and it is true and the mail camposerview shows the attachment icon representation....
Rambo
+1  A: 

I have tried to attach .csv file with "text/plain" & I got success. I think you should try the same. best of luck.

sugar
A: 

In my situation the email was sent fine from my iPhone, but there was no attachment when sending from my wife's iPhone. Turns out that her default account was set to her Yahoo account and that was not allowing attachments. I simply switched it to her mobile Me account and the attachment was made. I use gmail so I never had a problem.

in addition, I had tried switching the MIME type from text/csv to text/plain and that did not help. It worked either way on my iPhone and not at all on my wife's.

Hope this helps!

arnjmllr
A: 

Did you solve the problem mate? I'm stuck with the same problem!