IPhone mail Programming

Source: Internet
Author: User

From http://blog.csdn.net/koupoo/article/details/6455289

AddMessageui.Framework # Import <messageui/messageui. h> Mfmailcomposeviewcontrollerdelegate
CodeAs follows:
# PragmaMark-
# PragmaMarkMfmailcomposeviewcontroller
- (Void)Alertwithtitle Nsstring *)_ Title _ msg Nsstring *)MSG{
Uialertview *Alert= [[UialertviewAlloc]Initwithtitle:_ Title _
Message:MSG
Delegate:Nil 
Cancelbuttontitle:@"OK" 
Otherbuttontitles:Nil];
[Alert show];
[Alert release];
}

-(Void)Displaycomposersheet{
Mfmailcomposeviewcontroller *Mailpicker= [[MfmailcomposeviewcontrollerAlloc]Init];
Mailpicker.Mailcomposedelegate= Self;

[Mailpicker setsubject:@"Email Subject"];

// Add a sender
Nsarray *Torecipients= [NsarrayArraywithobject:@" First@example.com "];
// Nsarray * ccrecipients = [nsarray arraywithobjects :@" Second@example.com ",@" Third@example.com ", Nil];
// Nsarray * bccrecipients = [nsarray arraywithobject :@" Fourth@example.com ", Nil];
[Mailpicker settorecipients:Torecipients];
// [Picker setccrecipients: ccrecipients];
// [Picker setbccrecipients: bccrecipients];

// Add an image
Uiimage *Addpic= [UiimageImagenamed:@"Icon.png"];
Nsdata *Imagedata= Uiimagepngrepresentation(Addpic);// PNG
// Nsdata * imagedata = uiimagejpegrepresentation (addpic, 1); // JPEG
[Mailpicker addattachmentdata:Imagedata mimetype:@""Filename:@"Icon.png"];

Nsstring *Emailbody= @"Email body";
[Mailpicker setmessagebody:Emailbody ishtml:Yes];

[SelfPresentmodalviewcontroller:Mailpicker animated:Yes];
[Mailpicker release];
}

-(Void)Launchmailappondevice{
Nsstring *Recipients= @"Mailto: first@example.com & subject = my email! ";
// @ "Mailto: first@example.com? Cc = second@example.com, Third@example.com & Amp; subject = my email! ";
Nsstring *Body= @"& Body = Email body! ";

Nsstring *Email= [NsstringStringwithformat:@"% @",Recipients,Body];
Email= [Email stringbyaddingpercentescapesusingencoding:Nsutf8stringencoding];

[[UiapplicationSharedapplication]Openurl:[NsurlUrlwithstring:Email];
}

-(Void)Sendemail{
ClassMailclass= (Nsclassfromstring(@"Mfmailcomposeviewcontroller"));

If (Mailclass! = Nil) {
If ([Mailclass cansendmail]) {
[SelfDisplaycomposersheet];
} Else {
[SelfLaunchmailappondevice];
}
} Else {
[SelfLaunchmailappondevice];
}
}

- (Void)Mailcomposecontroller Mfmailcomposeviewcontroller *)Controller
Didfinishwithresult Mfmailcomposeresult)Result Error Nserror *)Error{
Nsstring *MSG;

Switch (Result) {
Case Mfmailcomposeresultcancelled:
MSG= @"Cancel email sending";
Break;
Case Mfmailcomposeresultsaved:
MSG= @"The email is successfully saved";
[SelfAlertwithtitle:NilMSG:MSG];
Break;
Case Mfmailcomposeresultsent:
MSG= @"Email sent successfully";
[SelfAlertwithtitle:NilMSG:MSG];
Break;
Case Mfmailcomposeresultfailed:
MSG= @"Email sending failed";
[SelfAlertwithtitle:NilMSG:MSG];
Break;
Default:
Break;
}

Nslog(@"Sending result: % @",MSG);
[SelfDismissmodalviewcontrolleranimated:Yes];
}

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.