1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init]; //发送者 testMsg.fromEmail = @"xyhuangjia@yeah.net"; //发送给 testMsg.toEmail = @"huangj@ywsoftware.com"; //抄送联系人列表,如:@"664742641@qq.com;1@qq.com;2@q.com;3@qq.com" // testMsg.ccEmail = @"lanyuu@live.cn"; // //密送联系人列表,如:@"664742641@qq.com;1@qq.com;2@q.com;3@qq.com" // testMsg.bccEmail = @"664742641@qq.com"; //发送邮箱的发送服务器地址 testMsg.relayHost = @"smtp.yeah.net"; //需要鉴权 testMsg.requiresAuth = YES; //发送者的登录账号 testMsg.login = @"xyhuangjia@yeah.net"; //发送者的登录密码 testMsg.pass = @"HJ19930112"; //邮件主题 testMsg.subject = [NSString stringWithCString:"来自iphone socket的测试邮件" encoding:NSUTF8StringEncoding ]; // testMsg.subject = @"测试数据"; testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS! // Only do this for self-signed certs! // testMsg.validateSSLChain = NO; testMsg.delegate = self; //主题 NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, @"This is a test message.\r\n支持中文。",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil]; //附件 NSString *vcfPath = [[NSBundle mainBundle] pathForResource:@"video.jpg" ofType:@""]; NSData *vcfData = [NSData dataWithContentsOfFile:vcfPath]; //附件图片文件 NSDictionary *vcfPart = [[NSDictionary alloc ]initWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"video.jpg\"",kSKPSMTPPartContentTypeKey, @"attachment;\r\n\tfilename=\"video.jpg\"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; //附件音频文件 NSString *wavPath = [[NSBundle mainBundle] pathForResource:@"push" ofType:@"wav"]; NSData *wavData = [NSData dataWithContentsOfFile:wavPath]; NSDictionary *wavPart = [[NSDictionary alloc ]initWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"push.wav\"",kSKPSMTPPartContentTypeKey, @"attachment;\r\n\tfilename=\"push.wav\"",kSKPSMTPPartContentDispositionKey,[wavData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; // testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,wavPart, nil]; testMsg.parts = [NSArray arrayWithObjects:plainPart, nil]; [testMsg send];
|