In my app i am pre-filling the email address when the user wants to email someone. i do this like this:
NSArray *toRecipients = [NSArray arrayWithObject:#"sales#microsmith.com"];
NSString *subjectStr = [[NSString alloc] initWithFormat:#"test subject"];
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setToRecipients:toRecipients];
[mailController setSubject:subjectStr];
[self presentModalViewController:mailController animated:YES];
[mailController release];
[subjectStr release];
this all works fine with no problems. However, i wanted to know if there was a way to change what showed in the "To:" field once the email opens.
For example, instead of showing - sales#microsmith.com, i would like it to show "Microsmith Sales".
Is that possible?
thanks in advance
Yep, just change the way your recipient strings are formatted:
NSArray* recipients = [NSArray arrayWithObject: #"Sales Dept <sales#example.com>"];
Related
EDIT: I eventually contacted Apple DTS. After I provided a stackshot from an affected user, DTS decided I should file a bug with Apple BugReporter. So, at this point, I think it's an issue with MFMailComposer, but it's unresolved. The Apple bug number is 13602051
I have a bug that has been coming up again and again in an app.
Some users who upgrade their iOS version report that they can no longer use the email export in my app, which uses MFMailComposer. The app freezes, and doesn't generate a crash report.
My code is pretty simple, and I can't reproduce the reported bug, but many users have now said this happens after an iOS update. Here is the code:
// using ARC, so no reference counting
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
#autoreleasepool {
if (gpxFilePath) {
NSData *gpx = [NSData dataWithContentsOfFile:gpxFilePath];
[controller addAttachmentData:gpx mimeType:#"text/gpx" fileName:[self cleanFileName]];
gpx = nil;
}
}
[controller setSubject:subject];
[controller setMessageBody:body isHTML:YES];
[[MAP_APP_DELEGATE mainController] presentModalViewController:controller animated:YES];
After this is called, the email view comes up, but then is unresponsive.
I'm using the next code for iOS 6.1 and it works for me.
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc]init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"subject"];
User *user = [user_array objectAtIndex:1];
NSArray *toRecipients = [NSArray arrayWithObjects:#"mail address", nil];
[mailer setToRecipients:toRecipients];
NSArray *cc = [NSArray arrayWithObjects:#"mail address", nil];
[mailer setCcRecipients:cc];
NSDictionary *dic = [one array objectAtIndex:0];
NSString *description = [dic objectForKey:#"Description"];
NSString *emailBody = description;
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
Remember that simulator is not able to send e-mail, so alert view will be shown in this case.
Note 1: presentModalViewController is deprecated in iOS 6.0
Note 2: try to send the email without data to check if this is what causes the issue
This should solve your problem.
[[MAP_APP_DELEGATE mainController] presentModalViewController:controller animated:YES];
controller = nil;
I have write code to send mail on button click.But i have email id programatically.
I have output like this.
email#gmail.com Send MailButton
Now when i click on Send MailButton then it open MFMailComposeViewController but to field is empty.Here email#gmail.com is change dynamically it's not fixed.
My code is
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([MFMailComposeViewController canSendMail])
{
NSString *emailBody;
emailBody=self.shareString;
//NSLog(#"EMail Body ---- %#",emailBody);
[picker setMessageBody:emailBody isHTML:YES];
[picker becomeFirstResponder];
[self presentModalViewController:picker animated:YES];
}
What should be change here required?
Use following code:
NSArray *tempArray = [[NSArray alloc] initWithObjects:#"abc#gmail.com", nil];
[picker setToRecipients:tempArray];
It's working properly for me.
Thanks,
Hemang.
Well you need to create an array for this first.
-(void)displayComposerSheetEmailUs{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from the App!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"abc#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = #"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
Im new to Iphone develoment can any one helpme in getting sample code in send the mail with attachment through SMTP using iphone.
i have tried the sample code from this following URL
http://code.google.com/p/skpsmtpmessage/
Thanks
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];
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):
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];
I am trying to send out an email with a .csv attachment on the iPad. I am using the MFMailComposer per many examples given which is displayed below. When sending out the email, I can see the correct file attachment in the MFMailComposer window, but when I receive the email, nothing is attached. Any guidance as to what I may be doing wrong would be appreciated. Thank you for your time,
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:#"Results for Participant %d.", [delegate participantNumber]]];
[mailViewController setMessageBody:[NSString stringWithFormat:#"The results for Participant %d in Study: %# are as follows:", [delegate participantNumber], [[delegate getAccountData:([delegate accountItems] * [delegate accountNumberInUse])] description]] isHTML:NO];
NSData *textData = [[NSData alloc] initWithContentsOfFile:dataFileName];
[mailViewController addAttachmentData:textData mimeType:#"text/csv" fileName:[NSString stringWithFormat:#"Participant_Info_#%d.csv", [delegate participantNumber]]];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
Check the content of the textData variable, also (just guessing from your code) the dataFileName needs to contain a full system path to the file, not just it's name!
NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:dataFileName ofType:nil];
Is there a way to get the "from" address of Mail and display it in MFMailComposeViewController?
Is it possible?
Any way to do that..
Please help....
This will fill your MFMailComposeViewController:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set up subject
[picker setSubject:mailSubjectString];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:recieverMailAdress];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = bodyString;
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
Edit:
I think you should have an look to skpsmtpmessage