Skpsmtpmessage is an iOS third-party background send mail library https://github.com/jetseven/skpsmtpmessage.git
Original address: http://www.cnblogs.com/U-tansuo/p/ios_send_email.html
-(void) Statrupload: (ID) sender
{
Skpsmtpmessage *testsend = [[Skpsmtpmessage alloc]init];
Testsend.fromemail = @ "Outgoing mailbox";
Testsend.toemail = @ "Mail Inbox";
Testsend.relayhost = @ "smtp.163.com";
Testsend.requiresauth = YES;
Testsend.login = @ "user name;
Testsend.pass = @ "password;
Testsend.subject = [NSString stringwithcstring: "Test" encoding:nsutf8stringencoding];
Testsend.ccemail = @ "CC Mail";
Testsend.wantssecure = YES;
Testsend.delegate = self;
Nsdictionary *plainpart = [nsdictionary dictionarywithobjectsandkeys:@ "Text/plain", Kskpsmtppartcontenttypekey,
@ "This is a tést messåge.", kskpsmtppartmessagekey,@ "8bit", Kskpsmtppartcontenttransferencodingkey,nil];
NSString *vcfpath = [[NSBundle mainbundle] pathforresource:@ "test" oftype:@ "VCF"];
NSData *vcfdata = [NSData Datawithcontentsoffile:vcfpath];
Contacts
Nsdictionary *vcfpart = [Nsdictionary dictionarywithobjectsandkeys:@ "text/directory;\r\n\tx-unix-mode=0644;\r\n\ Tname=\ "test.vcf\" ", Kskpsmtppartcontenttypekey,
@ "attachment;\r\n\tfilename=\" test.vcf\ "", Kskpsmtppartcontentdispositionkey,[vcfdata EncodeBase64ForData], kskpsmtppartmessagekey,@ "base64", Kskpsmtppartcontenttransferencodingkey,nil];
Send picture attachment
NSString *imgpath = [[NSBundle mainbundle] pathforresource:@ "test" oftype:@ "jpg"];
NSData *imgdata = [NSData Datawithcontentsoffile:imgpath];
Nsdictionary *imagepart = [Nsdictionary dictionarywithobjectsandkeys:@ "Image/jpg;\r\n\tx-unix-mode=0644;\r\n\tname =\ "Test.jpg\" ", Kskpsmtppartcontenttypekey,
@ "attachment;\r\n\tfilename=\" test.jpg\ "", Kskpsmtppartcontentdispositionkey,[imgdata EncodeBase64ForData], kskpsmtppartmessagekey,@ "base64", Kskpsmtppartcontenttransferencodingkey,nil];
Send Video Accessories
Attach Video
NSString *videopath = [[NSBundle mainbundle] pathforresource:@ "video" oftype:@ "mov"];
NSData *videodata = [NSData Datawithcontentsoffile:videopath];
Nsdictionary *videopart = [Nsdictionary dictionarywithobjectsandkeys:@ "video/quicktime;\r\n\tx-unix-mode=0644;\r\n \tname=\ "Video.mov\" ", Kskpsmtppartcontenttypekey,
@ "attachment;\r\n\tfilename=\" video.mov\ "", Kskpsmtppartcontentdispositionkey,[videodata EncodeBase64ForData], kskpsmtppartmessagekey,@ "base64", Kskpsmtppartcontenttransferencodingkey,nil];
Testmsg.parts = [Nsarray arraywithobjects:plainpart,vcfpart, Imagepart, Videopart, nil];
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{
[Testsend send];
});
}
iOS Development note--ios background send mail