如何通过iPhone App /中的编程在电子邮件中添加附件和签名

时间:2012-03-15 11:42:48

标签: iphone html ios email-integration

如何在iPhone应用iPhone的电子邮件中以编程方式将视频/图像/音频添加为附件,如何添加Signature?我认为可以通过使用html标签来完成它,但是如何完成它。你能为此取得任何示例代码吗? 谢谢 -

1 个答案:

答案 0 :(得分:3)

发送附件:您可以使用MFMailComposeViewController从您的应用发送附件。

1。添加MessageUI框架,然后执行#import <MessageUI/MFMailComposeViewController.h>

2。在您的电子邮件按钮操作中,或者您要发送电子邮件时,请添加:

if([MFMailComposeViewController canSendMail]) //IMPORTANT: check if mail can be sent to avoid crash
{
    MFMailComposeViewController*mailController=[[MFMailComposeViewController alloc] init];

    NSURL*yourUrl=[NSURL fileURLWithPath:yourFilePath];
    NSData*attachData=[NSData dataWithContentsOfURL:yourUrl];

    mailController.mailComposeDelegate=self;
    [mailController addAttachmentData:attachData mimeType:@"yourExtension" fileName:@"yourFileName.yourExtension"];
    [mailController setSubject:@"Test Subject"];
    [mailController setTitle:@"Test Title"];


    if(mailController!=nil)
    {
        [self presentModalViewController:mailController animated:YES];
    }

    [mailController release];
}

else //give a prompt showing no mail accounts found
{
    UIAlertView*emailAlert=[[UIAlertView alloc] initWithTitle:@"No Email Account Found." message:@"Please set an email account." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [emailAlert show];
    [emailAlert release];
}

设置签名:我猜它使用相对于已设置的邮件帐户的签名。很抱歉不知道如何以编程方式更改它。