iPhone:使用自定义内容类型发送电子邮件
Posted
技术标签:
【中文标题】iPhone:使用自定义内容类型发送电子邮件【英文标题】:iPhone: Send E-Mail with Custom Content-Type 【发布时间】:2011-05-20 21:20:13 【问题描述】:我尝试从具有自定义 Content-Type 的应用程序发送电子邮件。
任何想法如何做到这一点?
所以我喜欢改变
“内容类型”: "multipart/mixed;boundary=Apple-Mail-1--209662383" --> "application/pkcs7-mime;name=smime.p7m;smime-type=envelope-data"
和 “内容传输编码”:
"7bit" --> "base64"
【问题讨论】:
有什么原因不能将其编码为附件吗? 是的,我不想发送加密的 smime 附件,然后 "Content-Type" 必须是 "application/pkcs7-mime; name=smime.p7m; smime-type=envelope-data"并且“Content-Transfer-Encoding”必须是“base64” 【参考方案1】:(void)launchInAppMail
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"In app email..."];
NSMutableString *messageString = [[NSMutableString alloc] init];
if (!(mNameField.text == nil || [mNameField.text isEqualToString:@""]))
[messageString appendFormat:@"Name: %@ \n",mNameField.text];
if (!(mPhoneNumberField.text == nil || [mPhoneNumberField.text isEqualToString:@""])) [messageString appendFormat:@"电话号码:%@ \n",mPhoneNumberField.text];
如果 (!(mEmailField.text == nil || [mEmailField.text isEqualToString:@""])) [messageString appendFormat:@"Email ID: %@ \n",mEmailField.text];
if (!(mTextView.text == nil || [mTextView.text isEqualToString:@""]))
[messageString appendFormat:@"Desription: %@ \n",mTextView.text];
if (!(mProblemNameButton.titleLabel.text == nil || [mProblemNameButton.titleLabel.text isEqualToString:@""]))
[messageString appendFormat:@"Problem Name: %@ \n",mProblemNameButton.titleLabel.text];
[messageString appendFormat:@"Address: %@ \n", self.mAddress];
if (self.coordinateLoc)
[messageString appendFormat:@"Longitude: %f, Latitude: %f \n", self.coordinateLoc.coordinate.longitude, self.coordinateLoc.coordinate.latitude];
[controller setToRecipients:[NSArray arrayWithObject:@"service@emergencylocksmithleads.com"]];
[控制器 setMessageBody:messageString ishtml:NO];
[messageString 发布];
if (mImageView.image != nil)
NSData *imageData = UIImageJPEGRepresentation(mImageView.image, 1);
[controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example.jpg"];
[self presentModalViewController:controller animated:YES];
[控制器释放];
pragma mark --------------------------------------------
pragma mark MFMailComposeViewController 委托方法
(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result 错误:(NSError )error
开关(结果)
案例 MFMailComposeResultCancelled:
NSLog(@"邮件发送取消。");
/
在此处执行取消事件的代码...
/
休息;
案例 MFMailComposeResultSaved:
NSLog(@"邮件已保存。");
/
在此处执行电子邮件保存事件的代码...
*/
休息;
案例 MFMailComposeResultSent:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sent" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.tag = 1;
alert.delegate = 自我;
[警报显示];
[警报发布];
休息;
案例 MFMailComposeResultFailed:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"邮件发送失败" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.tag = 2;
alert.delegate = 自我;
[警报显示];
[警报发布];
休息;
默认值:
休息;
[控制器dismissModalViewControllerAnimated:YES];
【讨论】:
这是发送邮件的代码,而不是更改邮件的“Content-Type”...【参考方案2】:我使用http://code.google.com/p/skpsmtpmessage/ 使用 ios 发送自定义邮件。
【讨论】:
以上是关于iPhone:使用自定义内容类型发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章
将基于送货方式的自定义文本添加到某些 WooCommerce 电子邮件通知
原创关于kindle加载电子书的方法之邮箱推送教程+手机(iPhone为例)下载文件后邮箱发送