url link is not getting sent from email [closed] - iphone

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In my iphone application, in MFMailComposer, I m adding an attachment. that attachment as a url link.in that link there is a pdf file. When I click send the url link is not sent to destination mail address.
I am using this code
-(void)sendMail
{
MFMailComposeViewController *mailView= [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate=self;
[mailView setSubject:titleString];
NSArray *array = [[NSArray alloc]initWithObjects:emailString, nil];
[mailView setToRecipients:array];
NSData *textData = [NSData dataWithContentsOfFile:self.fileString];
[mailView addAttachmentData:textData mimeType:#"text/plain" fileName:self.fileString];
[mailView setMessageBody:self.templatetextstring isHTML:YES];
[self presentModalViewController:mailView animated:YES];
}

Use this code
NSString *link = [NSString stringWithFormat:#"http://www.google.com"];
[controller setMessageBody:[NSString stringWithFormat:#"<p><font size=\"2\" face=\"Helvetica\"><a href=%#></br>%#</br></a></br></font></p>",link,#"Google"] isHTML:YES];
Hope it helps you..

I am not sure I understand your question probably whether you want to attach a pdf document or whether you just want to add a link to a pdf document so I will answer both. Here is the code I use to attach pdf data onto an email
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[cantSend show];
} else {
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
[mailView setSubject:#"PDF Attached to email"];
// Adding an actual PDF document to the email.
[mailView addAttachmentData:(__bridge NSData *)myPDFData mimeType:#"pdf" fileName:#"AttachedPDFDocument"];
[mailView setMessageBody:[NSString stringWithFormat:#"Sending %#. This email maybe sent as junk mail",fileName] isHTML:NO];
[self presentModalViewController:mailView animated:YES];
}
}
Notice I am adding the pdf data and not the actual pdf and then I set the extension (MimeType) to pdf and then set the name of the file it is that simple to add an attachment onto an email you are constructing.
To add a link to an email it is as simple as
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[cantSend show];
} else {
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
[mailView setSubject:#"PDF Link added in HTML"];
// Adding a HTML Link to an email. Remembering to set the Message to allow HTML.
NSString *link = [NSString stringWithFormat:#"http://www.google.com"];
[mailView setMessageBody:[NSString stringWithFormat:#"<p><font size=\"2\" face=\"Helvetica\"><a href=%#></br>%#</br></a></br></font></p>",link,#"Google"] isHTML:YES];
[self presentModalViewController:mailView animated:YES];
}
}
Notice that you aren't attaching any data put you are setting the setMessage to use HTML whereas the first example doesn't use HTML. This will now allow you to set an NSString in the message body that contains html elements.
EDIT
myPDFData is a CFDataRef of the dataContent of the PDF that I download from a webservice then the user can forward it to themselves via an email. If you are using ARC then you will need to add the bridge in (__bridge NSData *)myPDFData when setting attachmentData.
Hope this helps.

Related

How to get value from UITextfield and sent it to email?

I've created an app which contains form and that have to filled up in appropiate text fields..now i need to get all data in textfield and it to be sent in email.here is my code for composing email
- (IBAction)compose:(id)sender
{
if (text1.text=#"" && text2.text=#"" && text3.text=#"" && text4.text=#"" && text5.text=#"") {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Please enter all the field details"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
}
else{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:[NSString stringWithFormat:#"Appointment From Mr/Mrs. %#",text1.text]];
NSArray *toRecipients = [NSArray arrayWithObjects:#"xxx#xxxx.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody =[NSString stringWithFormat:#"Name =%#\nDate= %#\nPreferred Time Slot= %#\nE-Mail=%#\nSpecific Requests=",text1.text,text2.text,text3.text,text4.text,text5.text];
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[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];
}
}
}
if all the text field is null it have to popup an alert.But i'm getting error?...guide me pls..
If you are wondering how to get the text from textfield, and send it, you will need to use textfield.text
NSString *emailBody = textField.text;
[mailer setMessageBody:emailBody isHTML:NO];
There can be two way -
You can create proprty for your text field, and then access like - myTextField.text where you want.
You can create a NSString property and set value in to this when text field has some text.
//this is one single line which return your textFiledData
your_text_field.text
Create a variable for ur textfield like IBOutlet UITextField * textFieldVar; and connect it to ur Text field in the nib , then using the following code u can get the text from the text field
NSString *emailBody = textFieldVar.text;
You can create the body of email as you want by appending the string with particular format
Like
User ID: 223984775(value from the textfieldUserID)
Name: XYZ(value from the textfieldName)
......
You can do this by appending the string as the user moves to the next text field to enter.
Use Nsstring "stringWithFormat" method to append the data in the body. Use \n and \t to give a Tabular structure to the body of email. Use formatting too

How to add attchment and signature in email through programming in iPhone App/

How can I add video/image/audio as an attachment programmatically in the email in iPhone app iPhone and how can I add Signature? I think it can be done by using html tags but how it can be done. Can you please any sample code for this.
Thanks-
To send attachments: You can use MFMailComposeViewController to send attachments from your app.
1. Add MessageUI framework, and do #import <MessageUI/MFMailComposeViewController.h>
2. In your email button action or however you are sending email, add :
if([MFMailComposeViewController canSendMail]) //IMPORTANT: check if mail can be sent to avoid crash
{
MFMailComposeViewController*mailController=[[MFMailComposeViewController alloc] init];
NSURL*yourUrl=[NSURL fileURLWithPath:yourFilePath];
NSData*attachData=[NSData dataWithContentsOfURL:yourUrl];
mailController.mailComposeDelegate=self;
[mailController addAttachmentData:attachData mimeType:#"yourExtension" fileName:#"yourFileName.yourExtension"];
[mailController setSubject:#"Test Subject"];
[mailController setTitle:#"Test Title"];
if(mailController!=nil)
{
[self presentModalViewController:mailController animated:YES];
}
[mailController release];
}
else //give a prompt showing no mail accounts found
{
UIAlertView*emailAlert=[[UIAlertView alloc] initWithTitle:#"No Email Account Found." message:#"Please set an email account." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[emailAlert show];
[emailAlert release];
}
To set signature: I guess it uses the signature relative to the mail account that has been set. Sorry no idea on how to change it programmatically.

Problem with MFMailComposeViewController - User Can't Edit Mail Body - iPhone

I usually use the below code to allow the user to submit feedback on my apps. However for some reason in my OpenGL app the below code has a problem. It opens the email form correctly, however the form is locked - i.e the user can't actually edit the body of the text. Can anybody spot why this is happening ?
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Feedback on Stop That Bomb Free !"];
NSArray *toRecipients = [NSArray arrayWithObject:#"anemail#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody =
[NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[inputController presentModalViewController:picker animated:YES];
[picker release];
From reading your code I can find some things you should change:
Replace:
NSString *emailBody = [NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
With:
NSString *emailBody = #"Hi Martin, I would like to make the following comment : ";
As you are not using any formatting; you dont need to call the class method to create the simple string.
The other thing you can change is the fact that you message does not contain HTML.
So you dont need isHTML:YES.
I have tested this successfully on a sample app.
I imagine the problem is with the view controller presenting the view, rather than the messageUI view.

Attaching plain text file using MFMailComposer in iPhone SDK

I've been trying to use MFMailComposer to send a text file with encrypted data within. The problem is my attachment never shows up when when the email arrives in the inbox. Instead, a line of "<br/><br/>" is always present. I'm assuming is has something to do with the mime type and the receivers mail server not know how to read the data but I just can't figure out a solution.
Anyone come across this before and have a solution?
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate =self;
[mailController setSubject:#"Records"];
[mailController setMessageBody:#"" isHTML:YES];
[mailController addAttachmentData:dataToBeEncrypted mimeType:#"text/plain" fileName:#"Records.txt"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
} else {
//Pop up a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Could not send email. Verify Internet conneciton and try again." delegate:nil cancelButtonTitle:#"Done" otherButtonTitles:nil];
[alert show];
[alert release];
}
Thanks for any help you can give!
Think I got a fix. I just took a shot in the dark after seeing another example and it seemed to work. For mimetype, I just put #"mime".
I'm a little weary of it, so I'll have to do some more testing to make sure the file always comes out correct.

MFMailComposeViewController : how do I embed a clickable URL link into the email message body

I want my app using the MFMailComposeViewController to send an email such that the recipient can click on the embedded url to open the corresponding web site.
MFMailComposeViewController does not appear to support this explicitly. Any ideas?
I deleted my previous answer as it was incorrect and irrelevant. After much hair pulling I finally figured out what was going on in my case and is probably what is happening in this question.
When you compose the HTML body for the MFMailComposeViewController you must put line breaks in the HTML. If any line is > 76 chars long, the body will be interpreted as follows:
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
If you put line breaks in, the Content-Transfer-Encoding: quoted-printable will not happen and everything works as expected. Assuming you have proper HTML.
As an example, build the body as follows:
NSMutableString *body = [NSMutableString string];
// add HTML before the link here with line breaks (\n)
[body appendString:#"<h1>Hello User!</h1>\n"];
[body appendString:#"Click Me!\n"];
[body appendString:#"<div>Thanks much!</div>\n"];
Cheers!
:) Yes, you can do this:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:subject];
[composer setMessageBody:message isHTML:YES];
where message is just an NSString with HTML content. Inside you can add all the HTML you want.
I have the same problem.
My link is HTML, I can see 'blue' but if I click it, doesn't open safari mobile. Is allowed to me edit the text.
In a class I have this:
-(id) init{
self = [super init];
if (self) {
if ([MFMailComposeViewController canSendMail]) {
self.mailComposeDelegate = self;
[self setSubject: #"Subject"];
[self setMessageBody: #"<h2>Body</h2><a href='http://www.google.com'>link example</a>" isHTML: YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Mail Accounts"
message:#"You don't have a Mail account configured, please configure to send email."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
return self;
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
[controller dismissModalViewControllerAnimated: YES];
}
Here you can see the iPad Screen shot:
If I send, and then I go to "Sent" Mailbox the link works, so I think the problem is the event which open the links.
Thanks.
Use setMessageBody:isHTML: and pass a proper HTML link in the body (your link text) and pass YES to the isHTML parameter.
did you try on your code your suggestion? I tried it before getting to this web site, and sorry to say, it doesn't work at all. The Link appears really in blue, the HTML is read as html, but no link is possible. When I click on the link I can just edit it....
Any better suggestion?