iPhone:使用自定义内容类型发送电子邮件

时间:2022-10-23 15:43:11

I try to send an e-mail from an app with an custom Content-Type.

我尝试使用自定义内容类型从应用程序发送电子邮件。

Any ideas how to do this?

任何想法如何做到这一点?

So i like to change

所以我想改变

"Content-Type": "multipart/mixed; boundary=Apple-Mail-1--209662383" --> "application/pkcs7-mime; name=smime.p7m; smime-type=enveloped-data"

“Content-Type”:“multipart / mixed; boundary = Apple-Mail-1--209662383” - >“application / pkcs7-mime; name = smime.p7m; smime-type = enveloped-data”

and "Content-Transfer-Encoding":

和“内容传输编码”:

"7bit" --> "base64"

“7bit” - >“base64”

2 个解决方案

#1


1  

I used http://code.google.com/p/skpsmtpmessage/ for sending an custom mail with iOS.

我使用http://code.google.com/p/skpsmtpmessage/与iOS发送自定义邮件。

#2


-1  

  • (void)launchInAppMail {

    (void)launchInAppMail {

    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];

    MFMailComposeViewController * controller = [[MFMailComposeViewController alloc] init];

    controller.mailComposeDelegate = self;

    controller.mailComposeDelegate = self;

    [controller setSubject:@"In app email..."];

    [controller setSubject:@“在app email ...”];

    NSMutableString *messageString = [[NSMutableString alloc] init];

    NSMutableString * messageString = [[NSMutableString alloc] init];

    if (!(mNameField.text == nil || [mNameField.text isEqualToString:@""])) {

    if(!(mNameField.text == nil || [mNameField.text isEqualToString:@“”])){

    [messageString appendFormat:@"Name: %@ \n",mNameField.text];
    

    } if (!(mPhoneNumberField.text == nil || [mPhoneNumberField.text isEqualToString:@""])) { [messageString appendFormat:@"Phone Number: %@ \n",mPhoneNumberField.text];

    } if(!(mPhoneNumberField.text == nil || [mPhoneNumberField.text isEqualToString:@“”])){[messageString appendFormat:@“Phone Number:%@ \ n”,mPhoneNumberField.text];

    }

    }

    if (!(mEmailField.text == nil || [mEmailField.text isEqualToString:@""])) { [messageString appendFormat:@"Email ID: %@ \n",mEmailField.text]; }

    if(!(mEmailField.text == nil || [mEmailField.text isEqualToString:@“”])){[messageString appendFormat:@“Email ID:%@ \ n”,mEmailField.text]; }

    if (!(mTextView.text == nil || [mTextView.text isEqualToString:@""])) {

    if(!(mTextView.text == nil || [mTextView.text isEqualToString:@“”])){

    [messageString appendFormat:@"Desription: %@ \n",mTextView.text];
    

    }

    }

    if (!(mProblemNameButton.titleLabel.text == nil || [mProblemNameButton.titleLabel.text isEqualToString:@""])) {

    if(!(mProblemNameButton.titleLabel.text == nil || [mProblemNameButton.titleLabel.text isEqualToString:@“”])){

    [messageString appendFormat:@"Problem Name:  %@ \n",mProblemNameButton.titleLabel.text];
    

    }

    }

    [messageString appendFormat:@"Address: %@ \n", self.mAddress];

    [messageString appendFormat:@“Address:%@ \ n”,self.mAddress];

    if (self.coordinateLoc)

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

    [controller setToRecipients:[NSArray arrayWithObject:@“service@emergencylocksmithleads.com”]];

    [controller setMessageBody:messageString isHTML:NO];

    [controller setMessageBody:messageString isHTML:NO];

    [messageString release];

    [messageString release];

    if (mImageView.image != nil) {

    if(mImageView.image!= nil){

    NSData *imageData = UIImageJPEGRepresentation(mImageView.image, 1);
    
    
    [controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example.jpg"];
    

    }

    }

    [self presentModalViewController:controller animated:YES];

    [self presentModalViewController:controller animated:YES];

    [controller release]; }

    [控制器发布]; }

pragma mark --------------------------------------------

pragma mark MFMailComposeViewController delegate Methods

  • (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError )error { switch (result) {
    case MFMailComposeResultCancelled:
    NSLog(@"Mail send canceled.");
    /
    Execute your code for canceled event here ... /
    break;
    case MFMailComposeResultSaved:
    NSLog(@"Mail saved.");
    /
    Execute your code for email saved event here ... */
    break;
    case MFMailComposeResultSent: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sent" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; alert.tag = 1; alert.delegate = self; [alert show]; [alert release]; break;
    } case MFMailComposeResultFailed: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sending Failed" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; alert.tag = 2; alert.delegate = self; [alert show]; [alert release]; break;
    } default:
    break;
    } [controller dismissModalViewControllerAnimated:YES]; }
  • (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)结果错误:(NSError)错误{switch(result){case MFMailComposeResultCancelled:NSLog(@“Mail send canceled。”); /在此处执行取消事件的代码... / break; case MFMailComposeResultSaved:NSLog(@“Mail saved。”); /在此执行您的电子邮件保存事件代码... * / break; case MFMailComposeResultSent:{UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Mail Sent”消息:nil delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil]; alert.tag = 1; alert.delegate = self; [警示显示]; [警告发布];打破; } case MFMailComposeResultFailed:{UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Mail Sending Failed”消息:nil delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil]; alert.tag = 2; alert.delegate = self; [警示显示]; [警告发布];打破;默认值:break; } [controller dismissModalViewControllerAnimated:YES]; }

#1


1  

I used http://code.google.com/p/skpsmtpmessage/ for sending an custom mail with iOS.

我使用http://code.google.com/p/skpsmtpmessage/与iOS发送自定义邮件。

#2


-1  

  • (void)launchInAppMail {

    (void)launchInAppMail {

    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];

    MFMailComposeViewController * controller = [[MFMailComposeViewController alloc] init];

    controller.mailComposeDelegate = self;

    controller.mailComposeDelegate = self;

    [controller setSubject:@"In app email..."];

    [controller setSubject:@“在app email ...”];

    NSMutableString *messageString = [[NSMutableString alloc] init];

    NSMutableString * messageString = [[NSMutableString alloc] init];

    if (!(mNameField.text == nil || [mNameField.text isEqualToString:@""])) {

    if(!(mNameField.text == nil || [mNameField.text isEqualToString:@“”])){

    [messageString appendFormat:@"Name: %@ \n",mNameField.text];
    

    } if (!(mPhoneNumberField.text == nil || [mPhoneNumberField.text isEqualToString:@""])) { [messageString appendFormat:@"Phone Number: %@ \n",mPhoneNumberField.text];

    } if(!(mPhoneNumberField.text == nil || [mPhoneNumberField.text isEqualToString:@“”])){[messageString appendFormat:@“Phone Number:%@ \ n”,mPhoneNumberField.text];

    }

    }

    if (!(mEmailField.text == nil || [mEmailField.text isEqualToString:@""])) { [messageString appendFormat:@"Email ID: %@ \n",mEmailField.text]; }

    if(!(mEmailField.text == nil || [mEmailField.text isEqualToString:@“”])){[messageString appendFormat:@“Email ID:%@ \ n”,mEmailField.text]; }

    if (!(mTextView.text == nil || [mTextView.text isEqualToString:@""])) {

    if(!(mTextView.text == nil || [mTextView.text isEqualToString:@“”])){

    [messageString appendFormat:@"Desription: %@ \n",mTextView.text];
    

    }

    }

    if (!(mProblemNameButton.titleLabel.text == nil || [mProblemNameButton.titleLabel.text isEqualToString:@""])) {

    if(!(mProblemNameButton.titleLabel.text == nil || [mProblemNameButton.titleLabel.text isEqualToString:@“”])){

    [messageString appendFormat:@"Problem Name:  %@ \n",mProblemNameButton.titleLabel.text];
    

    }

    }

    [messageString appendFormat:@"Address: %@ \n", self.mAddress];

    [messageString appendFormat:@“Address:%@ \ n”,self.mAddress];

    if (self.coordinateLoc)

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

    [controller setToRecipients:[NSArray arrayWithObject:@“service@emergencylocksmithleads.com”]];

    [controller setMessageBody:messageString isHTML:NO];

    [controller setMessageBody:messageString isHTML:NO];

    [messageString release];

    [messageString release];

    if (mImageView.image != nil) {

    if(mImageView.image!= nil){

    NSData *imageData = UIImageJPEGRepresentation(mImageView.image, 1);
    
    
    [controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example.jpg"];
    

    }

    }

    [self presentModalViewController:controller animated:YES];

    [self presentModalViewController:controller animated:YES];

    [controller release]; }

    [控制器发布]; }

pragma mark --------------------------------------------

pragma mark MFMailComposeViewController delegate Methods

  • (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError )error { switch (result) {
    case MFMailComposeResultCancelled:
    NSLog(@"Mail send canceled.");
    /
    Execute your code for canceled event here ... /
    break;
    case MFMailComposeResultSaved:
    NSLog(@"Mail saved.");
    /
    Execute your code for email saved event here ... */
    break;
    case MFMailComposeResultSent: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sent" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; alert.tag = 1; alert.delegate = self; [alert show]; [alert release]; break;
    } case MFMailComposeResultFailed: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mail Sending Failed" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; alert.tag = 2; alert.delegate = self; [alert show]; [alert release]; break;
    } default:
    break;
    } [controller dismissModalViewControllerAnimated:YES]; }
  • (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)结果错误:(NSError)错误{switch(result){case MFMailComposeResultCancelled:NSLog(@“Mail send canceled。”); /在此处执行取消事件的代码... / break; case MFMailComposeResultSaved:NSLog(@“Mail saved。”); /在此执行您的电子邮件保存事件代码... * / break; case MFMailComposeResultSent:{UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Mail Sent”消息:nil delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil]; alert.tag = 1; alert.delegate = self; [警示显示]; [警告发布];打破; } case MFMailComposeResultFailed:{UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Mail Sending Failed”消息:nil delegate:self cancelButtonTitle:@“OK”otherButtonTitles:nil]; alert.tag = 2; alert.delegate = self; [警示显示]; [警告发布];打破;默认值:break; } [controller dismissModalViewControllerAnimated:YES]; }