iOS Call System Feature email

Source: Internet
Author: User
Tags mail account
<span id="Label3"></p><p><p>Send mail using Mfmailcomposeviewcontroller</p></p><p><p>1. The project needs to be imported into the Framework: messageui.framework</p></p><p><p>2. Add Agent mfmailcomposeviewcontrollerdelegate to The. H file of the controller used and import header file: #import <MessageUI/MessageUI.h></p></p><p><p>3. Determine if the user has set up a mailbox account</p></p><pre>BOOL Cansend =<span style="color: #000000;"><span style="color: #000000;">[mfmailcomposeviewcontroller cansendmail];</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(cansend) {[self sendemailaction];}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{ </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Prompt user to add mail account</span></span>Uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Add Your Mail account:</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Message<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Settings->mail,contacts,calendars->add</span> account</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">preferredstyle:uialertcontrollerstylealert]; Uialertaction</span></span>*defaultaction = [uialertaction Actionwithtitle:[kglobal getstringvaluewithkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">OK</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>] Style:uialertactionstyledefault handler:^ (uialertaction *<span style="color: #000000;"><span style="color: #000000;">_nonnull Action) {}]; [alert addaction:defaultaction]; [self Presentviewcontroller:alert Animated:yes completion:nil];}</span></span></pre><p><p>4.sendEmailAction Method Code</p></p><pre>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) sendemailaction{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Mail Server</span></span>Mfmailcomposeviewcontroller *mailcompose =<span style="color: #000000;"><span style="color: #000000;">[[mfmailcomposeviewcontroller alloc] init]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a mail agent</span></span><span style="color: #000000;"><span style="color: #000000;">[mailcompose setmailcomposedelegate:self]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set Message subject</span></span>[mailcompose setsubject:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">I am the subject of the mail</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set Recipient</span></span>[mailcompose settorecipients:@[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Set cc people</span></span>[mailcompose setccrecipients:@[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set up a CC</span></span>[mailcompose setbccrecipients:@[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">[email protected]</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]]; </span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* * Set the body content of the message</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">NSString</span></span>*emailcontent =<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">I am the email content</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">is <span style="color: #008000;">HTML format</span></span><span style="color: #000000;"><span style="color: #000000;">[mailcompose setmessagebody:emailcontent ishtml:no]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">If you are using HTML format, the following code</span></span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">* NSData *imagedata = <span style="background-color: #ffffff;">UIImage<span style="color: #ff0000;">JPEG</span>representation</span>(self.cellimage, 0.5); NSString *encodedstring = [imageData base64encodedstringwithoptions:nsdatabase64encodingendlinewithcarriagereturn] ; NSString *emailcontent = [nsstring stringwithformat:@ "<! DOCTYPE HTML public \ "-//w3c//dtd XHTML 1.0 strict//en\" \ "</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-STRICT.DTD</span></span><span style="color: #008000;">\ ">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.