I add .jpg this way:
UIImage *sentPic = self.image;
NSData *imageData = UIImageJPEGRepresentation(sentPic, 1);
[picker addAttachmentData:imageData mimeType:#"image/jpg" fileName:#"pic.jpg"];
I change it to "image/gif".But it doesn't work fine. Th Gif is just a still image in the mail.
NSData *imageData = [[NSData alloc] initWithContentsOfFile:pathToGifFile];
[picker addAttachmentData:imageData mimeType:#"image/gif" fileName:#"pic.gif"];
[imageData release];
This would add it as attachment, but I'm not sure if that's what you want, or you want to display the image inside the message?
Have you ever tried HTML code in your email like this:
NSString *emailBody = #"It is a gif email!";
emailBody = [EmailBody stringByAppendingString:#"<img src='http://xx.xx.pic.gif'>"];
[picker setMessageBody:emailBody isHTML:YES];
The code I haven't tested, you can have a try. Tell us if it works.
I just tested this. Works great:
NSString *pathForGif = [[NSBundle mainBundle] pathForResource: #"<your file name>" ofType: #"gif"];
NSData *gifData = [NSData dataWithContentsOfFile: pathForGif];
[mailController addAttachmentData:gifData mimeType:#"image/gif" fileName:#"EmailGIF.gif"];
[self presentModalViewController:mailController animated:YES];
Related
I have a pdf file called FlashCards.pdf
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
NSArray *recipients = #[#"aarone_2010#hotmail.com"];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:#"FlashCards" ofType:#"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/pdf" fileName:#"FlashCards"];
[picker setSubject:#"Flashcards"];
[picker setToRecipients:recipients];
[picker setMessageBody:#"Hello" isHTML:NO];
[picker setMailComposeDelegate:self];
[self presentViewController:picker animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
The email is being sent and it seems that everything is working, but it's not sending the PDF file.
EDIT:
This actually works, I had other problems in other parts of my code. My problem is solved. I also made sure that the extensions were correct instead of having FlashCards as a file name, it should be FlashCards.pdf This is the exact code I have working:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
NSArray *recipients = #[#"android.aaron.david#gmail.com"];
NSString *path = [[NSBundle mainBundle] pathForResource:#"FlashCards" ofType:#"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/pdf" fileName:#"FlashCards.pdf"];
[picker setSubject:#"Flashcards"];
[picker setToRecipients:recipients];
[picker setMessageBody:#"Hello" isHTML:NO];
[picker setMailComposeDelegate:self];
[self presentViewController:picker animated:YES completion:nil];
Use MIME type text/x-pdf instead of application/pdf. Also check the size/length of myData to verify that the PDF was loaded.
When adding an attachment to an email, the file name gets it's complete path.
For a file located in:
/var/mobile/Applications/C3BBAA5F-07FE-4E26-9661-CB492E06BD2E/Documents/
I'm getting as a result, a file named:
_var_mobile_Applications_C3BBAA5F-07FE-4E26-9661-CB492E06BD2E_Documents_Clock.sqlite
When I need my filename to be:
Clock.sqlite
Here's my code:
NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/x-sqlite3" fileName:path];
How can I get the attachment to have only the filename and extension, without the complete path?
Thank you!
This should do what you want:
NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/x-sqlite3" fileName:[path lastPathComponent]];
i try to send a audio record by file aac (kAudioFormatMPEG4AAC) format but the file attached it's doesn't send
*myString = file://localhost/private/var/mobile.......
here is my code
MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"My Audio File"];
NSString *fileName = #"Rec.aac";
NSString *documentsDirectory = myString ;
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
NSData *data = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:data mimeType:#"audio/aac"
fileName:fileName];
NSString *emailBody = #"AAC format sound file attached.";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
NSData *data = [NSData dataWithContentsOfFile:path];
You're passing in a file:// URL, which won't be understood by that method. That method expects just a standard file path, i.e. /private/var/mobile/.
You could simply use the file path, but if you're only provided with a URL form string, you can create a URL object and use that with NSData.
NSURL* fileURL = [NSURL URLwithString:myString];
NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:fileURL options:0 error:&error];
if (error) {
NSLog(#"Unable to load file from provided URL %#: %#", myString, error);
}
how to insert uiimage into body of mail composer window.. i have with this code:
NSMutableString *emailBody = [[[NSMutableString allocinitWithString:#""] retain];
[emailBody appendString:#" type text here"];
UIImage *emailImage = [UIImage imageNamed:#"20-gear2.png"]; NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
NSString *base64String = [imageData base64EncodedString];
[emailBody appendString:[NSString stringWithFormat:#"",base64String]];
NSLog(#"emailBody....%#", emailBody);
[emailBody appendString:#""];
NSLog(#"emailBody1....%#", emailBody);
MFMailComposeViewController *mailComposerController = [[MFMailComposeViewController alloc] init];
[mailComposerController setSubject:#"Your subject"];
[mailComposerController setMessageBody:nil isHTML:YES];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:"your image.png"]);
[mailComposerController addAttachmentData:imageData mimeType:#"image/png" fileName:#"image.png"];
Hope this help you...
NSData *imageData = UIImagePNGRepresentation(yourImage);
[mailController addAttachmentData:imageData mimeType:#"image/png" fileName:imageName];
i hav a file with some data and i want to attach this file to mail, and i am using the default mail composer ...
any idea how to attach the file to mail before sending to receipents....
Thanks in advance....
Example with an attached image:
NSData *myData = UIImagePNGRepresentation(myImage);
[mailComposer addAttachmentData:myData mimeType:#"image/png" fileName:#"MyImage"];
NSString *path = [[NSBundle mainBundle] pathForResource:#"bg" ofType:#"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[controller addAttachmentData:myData mimeType:#"image/jpg" fileName:#"Attachment-1"];
[self presentModalViewController:controller animated:YES];