email functionality is not working fine - iphone

I have used the MFMailComposeViewController for sending the email in my code. I have also used the reachability code to check the internet connection. Internet connection is working fine. Whenever I used to send a mail from my code I got the message that email has been sent. But I didn't get any mail. There is no email which is sending from the app. I don't what is the reason behind this. If someone know how to get rid of this problem please provide me some solution.
-(void)sendemail
{
emailBody = #"";
mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:#"Report"];
NSURL *url = [NSURL URLWithString:imagePath];
NSData *data = [NSData dataWithContentsOfURL:url];
[mail addAttachmentData:data mimeType:#"image/jpg" fileName:#"licence.png"];
NSMutableString *breakline = [[NSMutableString alloc]init];
[breakline appendString:[NSString stringWithFormat:#"<br>"]];
NSArray *toRecipients = [NSArray arrayWithObject:#"m.garg#ldh.01s.in"];
[mail setToRecipients:toRecipients];
emailBody = [emailBody stringByAppendingFormat:#"%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#",#"Name: ",namestr,breakline,#"Address: ", addresstr,breakline,#"Landmark: ",landmarkstr,breakline,#"City: ", citystr,breakline,#"State: ", statestr,breakline,#"PIN: ", pinstr,breakline,#"Contact No: ",phonestr,breakline,#"Licence:",licencestr,breakline,#"Email Id", emailstr];
[mail setMessageBody:emailBody isHTML:YES];
if (mail != nil) {
[self presentModalViewController: mail animated: YES];
[mail release];
}
}
Thanks to all.

Simply try something like this:
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
[controller setToRecipients:[NSArray arrayWithObject:#"123#abc.com.pk"]];
controller.mailComposeDelegate = self;
[controller setSubject:#""];
[controller setMessageBody:#"" isHTML:NO];
if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
}
and don't forget to add the following delegate method for returning to your app:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(#"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}

I wonder if your "to recipients" array is being freed before the email got sent.
Are your recipent emails showing in the "Send To" field when the mail composer view controller appears ?

Related

how to set email Receptionit a NSString in iphone application

I am sending email from iphone app and i want that email sent to should be the value or address the var emailTO has should be in TO automatically.
NSString*emailTO=#"ali#yahoo.com";
[picker setRecipients:[NSArray arrayWithObject:emailTO]];
but it does not work any idea how to implement in this way thanks
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setToRecipients:[NSArray arrayWithObject:[NSString stringWithFormat:#"%#,#"ur Receipent data"]]]];
Try to use this one...
NSArray *array = [NSArray arrayWithObject:#"ali#yahoo.com"];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:array];
[self presentViewController:mailViewController animated:YES completion:NULL];
}
else
{
NSLog(#"Device is unable to send email in its current state.");
}
Try This. Hope will Help You.Note that you will need to add the MessageUI framework to your app.
#import <MessageUI/MessageUI.h>
and
MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
[mail setToRecipients:[NSArray arrayWithObject:#"email#gmail.com"]];
[mail setSubject:#"Set Your Subject Here"];
[self presentModalViewController:mail animated:YES];
Use MFMailComposeViewControllerDelegate protocol: Delegate Function for conform the result
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(#"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(#"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Result: failed");
break;
default:
NSLog(#"Result: not sent");
break;
}
}
Description
setToRecipients:
Sets the initial recipients to include in the email’s “To” field.
- (void)setToRecipients:(NSArray*)toRecipients
Parameters
toRecipients
An array of NSString objects, each of which contains the email address of a single recipient.
try this
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[picker setRecipients:[NSArray arrayWithObject:#"your email address"]];
[self presentViewController:mailViewController animated:YES completion:nil];
If you want to open iPhone Email application, then use below code.So, you have not any need to add MFMailComposeViewController.
NSString *subject = #"";
NSString *body = #"";
NSString *address = #"test#gmail.com";
NSString *cc = #"";
NSString *path = [NSString stringWithFormat:#"mailto:%#?cc=%#&subject=%#&body=%#", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:url];
You should use
[picker setRecipients:[NSArray arrayWithObjects:emailTO,nil]];

How to open mail within the app from webview?

This is my code..
if ([ [ requestURL scheme ] isEqualToString: #"mailto" ])
{
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
NSString *strEmail = [NSString stringWithFormat:#"%#",requestURL];
NSString *subString = [[strEmail componentsSeparatedByString:#":"] lastObject];
[composer setToRecipients:[NSArray arrayWithObjects:subString, nil]];
[composer setSubject:#"Kreativ-Q"];
[composer setMessageBody:#"" isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
}
But when i click on the link in webview it is opening in mailBox. and when i send or cancel the mail from there and go back to my app the mail was still there. They show me twice. I just want, it would open in my app only..
Thanks in advance.
May help you:
Set this delegate in your .h file if you didnt.
<MFMailComposeViewControllerDelegate>

can't set Mailto field in MFMailComposeViewController in iphone

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

Mailbox programming in iphone?

I want saved email addresses of different users, and I want to open mailBox's new mail when I click the email, same as phonebook email in iphone,
what should I to do ???
You should use the MFMailComposeViewController class, and the implement MFMailComposeViewControllerDelegate protocol,
First to send a message:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"My Subject"];
[controller setMessageBody:#"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
Once you sent you will get delegate callback in mailComposeController :
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(#"It's gone!");
}
[self dismissModalViewControllerAnimated:YES];
}
Create new message within Mail:
NSString *subject = #"The subject";
NSString *body = #"The message";
NSString *address = #"mail#address.com";
NSString *cc = #"mail#address.com";
NSString *path = [NSString stringWithFormat:#"mailto:%#?cc=%#&subject=%#&body=%#", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];

Not receiving attachments sent from MFMailComposer

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