将HTML内容设置为MFMailComposeViewController视图的邮件正文

时间:2012-05-07 13:31:34

标签: objective-c ios email xcode4 messageui

我正在使用MessageUI框架在我的应用中撰写电子邮件。我想为邮件正文设置HTML内容。

所以我提到Mugunthkumar's blog,我编码如下,

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

当我运行应用程序并转到电子邮件撰写视图时,我收到以下邮件正文,

enter image description here

我正在使用XCode4和iOS 4.3。 我的代码没有任何问题。 但我需要将可点击的URL插入我的邮件正文。

请帮助!!

1 个答案:

答案 0 :(得分:4)

如果要发送HTML格式的电子邮件,则转义电子邮件正文中的HTML标记是错误的。使用</a>代替&lt;/a&gt;