【问题标题】:iPhone: Send E-Mail with Custom Content-TypeiPhone:使用自定义内容类型发送电子邮件
【发布时间】:2023-03-10 13:49:01
【问题描述】:

我尝试从具有自定义 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”

标签: iphone email iphone-sdk-3.0 ios ios4


【解决方案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 发送自定义邮件。

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 2013-08-29
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多