Set HTML content to the mail body of MFMailComposeViewController's view - objective-c

I'm using MessageUI framework to compose email in my app. I want set HTML content for the mail body.
So I refered Mugunthkumar's blog and I coded as follow,
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from California!"];
// 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];
// Fill out the email body text
NSString *pageLink = #"http://mugunthkumar.com/mygreatapp"; // replace it with yours
NSString *iTunesLink = #"http://link-to-mygreatapp"; // replate it with yours
NSString *emailBody =
[NSString stringWithFormat:#"%#\n\n<h3>Sent from <a href = '%#'>MyGreatApp</a> on iPhone. <a href = '%#'>Download</a> yours from AppStore now!</h3>", #"title", pageLink, iTunesLink];
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
When I ran the app and go to the email compose view, I'm getting the following mail body,
I'm using XCode4 and iOS 4.3.
I can not see any issue with my code.
But I need to insert clickable URLs to my mail body.
please help !!

If you want to send an HTML-formatted email, it is wrong to escape the HTML tags in the email body. Use </a> instead of </a> etc.

Related

Image from app to mail

How can I do something like "share to mail"? Like in NSSharingServices when selecting mail. For example I have NSImage and I want to achieve result like in image2. How can I do it? Any pointers?
Image1:
Image2:
To create message from text only I can do:
NSURL * url;
url = [NSURL URLWithString:#"mailto:"
"?subject="
"&body=text"
];
(void) [[NSWorkspace sharedWorkspace] openURL:url];
but I don't know what to do to create message with image.
I found a way to add attachment when using ScriptingBridge framework. Code:
MailApplication *mail = [SBApplication
applicationWithBundleIdentifier:#"com.apple.Mail"];
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:#"outgoing message"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
#"this is my subject", #"subject",
#"this is my content", #"content",
nil]];
[[mail outgoingMessages] addObject: emailMessage];
emailMessage.visible = YES;
NSString *attachmentFilePath = [NSString stringWithUTF8String:"<my provided file path>"];
if ( [attachmentFilePath length] > 0 ) {
MailAttachment *theAttachment = [[[mail
classForScriptingClass:#"attachment"] alloc]
initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
attachmentFilePath, #"fileName",
nil]];
[[emailMessage.content attachments] addObject: theAttachment];
}
[emailMessage visible];
It works. But how to add NSImage to attachment? Maby I have to write NSImage to temporary file, then add as attachment and delete temporary file? Or what? Or maby I should somehow add NSImage to body?
like this:
NSString *text = #"sometext";
NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:#"/logo57.png"]];
NSArray * shareItems = [NSArray arrayWithObjects:text, image, nil];
NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
service.delegate = self;
[service performWithItems:shareItems];
also make sure you put the NSSharingServiceDelegate in your headerfile of the delegate.

iOs Custom scheme in MFMailComposeViewController

I'm trying to send via MFMailComposeViewController a custom url scheme so that the receipient could tap on the embedded link and open my application on his iphone.
So far the receipient gets an email but nothing happens when he taps on the LINK.
here is the code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
[picker setSubject:#"Incoming task"];
// Fill out the email body text
NSString * types = #"";
for(NSString *type in task.location_types){
types = [types stringByAppendingFormat:#"%#|",type];
}
if(types.length > 1){
types = [types substringToIndex:types.length - 1];
}
NSString *desc = [task.description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE<script type=\"text/javascript\" charset=\"utf-8\">function doSomething() { window.location = \"%#\;return false;}</script>",link];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[controller presentModalViewController:picker animated:YES];
[picker release];
helpy://?taskid=..... is my custom registered URL Scheme and if I type it from the address bar of the browser it opens up my application on the iPhone.
For some reason when this link is embedded into email, tapping it does not do anything.
Any help?
thanks
I highly doubt that Mail will execute JavaScript on iOS (even on the desktop I highly doubt it, but haven't tried it though). Simply set the URL as the href attribute of your hyperlink and everything should work fine. Any reason why you want to do it with JavaScript? I'm just curious ;-)
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE", link];

change a copy of a sound file name before email it

I am sending a sound file to email , but i want to change its name just for the email.
lets say i take some sound.caf , in my folder , i want to leave its name just like that ,but to take a copy of it ,change its name, and then send it.
i will show how i send email, and i need the simplest way to change the file name without affecting the original :
//send email log-------------------------
NSLog(#"mail");
[[CCDirector sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:#"your email"];
[picker setToRecipients:toRecipients];
NSString *sound=[NSString stringWithFormat:#"sound%d.caf",[memoryInstnace getSoundToEdit]]; //here, i need to change the name of the copy .
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths2 objectAtIndex:0] stringByAppendingPathComponent:sound];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[picker addAttachmentData:data mimeType:#"caf" fileName:sound];//
NSString *emailBody = #"my sound ";
[picker setMessageBody:emailBody isHTML:NO];
[picker setSubject:#" new message "];
//display the view
[[[CCDirector sharedDirector] view] addSubview:picker.view];
//[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
Simply put the file name you like here:
[picker addAttachmentData:data mimeType:#"caf" fileName:myFileName];
and it will be received as myFileName instead of sound. Indeed, you are just attaching some data to your email message; this is unrelated to where the data came from (it could be a file, the network, etc); when attaching, you specify the name under which the data will be recognized as an attachment on the receiving end.

How to tag users in a photo using the Facebook iOS SDK?

I can't seem to work out how to tag users in a Facebook photo upload.
The documentation seems to suggest that you use an array, but the following code doesn't parse correctly (causes an application crash)
- (void)uploadImage:(UIImage *)img
withTags:(NSArray *)tags
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"msgstring", #"message",
img, #"picture",
nil];
if (tags) {
[params setObject:tags
forKey:#"tags"];
}
self.requestType = FBAssistantRequestImageUpload;
[self.facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
It works fine without the tags. The array at the moment contains a single string with the identifier of the friend I wish to tag.
I assume I'm adding the tags incorrectly. I was hoping to avoid having to use the three-step method outlined here: Tag Friends in Facebook Photo Upload, as I believe that requires photos permission, which just posting the photo doesn't need.
here's the code I use to tag friends on photos:
NSMutableArray *tags = [[NSMutableArray alloc] init];
NSString *tag = nil;
if(self.selectedFriends != nil){
for (NSDictionary *user in self.selectedFriends) {
tag = [[NSString alloc] initWithFormat:#"{\"tag_uid\":\"%#\"}",[user objectForKey:#"id"] ];
[tags addObject:tag];
}
NSString *friendIdsSeparation=[tags componentsJoinedByString:#","];
NSString *friendIds = [[NSString alloc] initWithFormat:#"[%#]",friendIdsSeparation ];
[params setObject:friendIds forKey:#"tags"];
}

Add default text to iOS mail composer

I have:
[mailComposer setMessageBody:[self currentText] isHTML:NO];
Where emailComposer is just the iOS email composer view. I want to add to currentText another string. How would I do this?
NSString *messageBody = [NSString stringWithFormat:#"%#%#", [self currentText], someOtherString];
[mailComposer setMessageBody:messageBody isHTML:NO];