**
最近公司做了一个项目,部分用户在国外,用手机注册接收验证码不是很方便,于是注册就分两种,国内用手机号,国外用邮箱,下面是用SMTPLibrary后台发送邮件的方法,我进行了简单的封装:
**
- (void)sendEmailTo:(NSString *)toEmail verifyCode:(NSString *)verifyCode
{
SKPSMTPMessage *myMessage = [[SKPSMTPMessage alloc] init];
myMessage.fromEmail = @"service@wiikang.com"; //发送邮箱
myMessage.toEmail = toEmail; //收件邮箱
myMessage.bccEmail = @"zgsh0916@126.com";//抄送
myMessage.bccEmail = @"zgsh0916@gmail.com";
myMessage.bccEmail = @"957027534@qq.com";
myMessage.relayHost = @"smtp.exmail.qq.com";//发送地址host 腾讯企业邮箱:smtp.exmail.qq.com
myMessage.requiresAuth = YES;
myMessage.login = @"service@wiikang.com";//发送邮箱的用户名
myMessage.pass = @"Wk_189";//发送邮箱的密码
myMessage.wantsSecure = YES;
myMessage.subject = @"小优健康管理平台";//邮件主题
myMessage.delegate = self;
NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,[NSString stringWithFormat:@"%@",verifyCode],kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey, nil];
myMessage.parts = [NSArray arrayWithObjects:param,nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[myMessage send];
});
}
**
发送成功回调
**
- (void)messageSent:(SKPSMTPMessage *)message
{
[MBProgressHUD showSuccess:@"邮件发送成功"];
WMLog(@"邮件发送成功");
}
**
发送失败回调
**
- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
[MBProgressHUD showError:@"邮箱发送失败,请检查您的网络是否正常"];
}
**
注意:用户注册为新浪邮箱时会造成崩溃,网上找了很多资料,没有发现解决办法,反正国外的用户用新浪的应该比较少吧,就没管它了
**