开发者

iPhone: Send E-Mail with Custom Content-Type

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"

and "Content-Transfer-Encoding":

"7bit" --> "base开发者_Python百科64"


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


  • (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:@"Phone Number: %@ \n",mPhoneNumberField.text];

    }

    if (!(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"]];

    [controller setMessageBody:messageString isHTML:NO];

    [messageString release];

    if (mImageView.image != nil) {

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

    }

    [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]; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜