**
最近公司做了一個項目辖众,部分用戶在國外和敬,用手機注冊接收驗證碼不是很方便,于是注冊就分兩種啤它,國內(nèi)用手機號舱痘,國外用郵箱,下面是用SMTPLibrary后臺發(fā)送郵件的方法芭逝,我進行了簡單的封裝:
**
- (void)sendEmailTo:(NSString *)toEmail verifyCode:(NSString *)verifyCode
{
SKPSMTPMessage *myMessage = [[SKPSMTPMessage alloc] init];
myMessage.fromEmail = @"service@wiikang.com"; //發(fā)送郵箱
myMessage.toEmail = toEmail; //收件郵箱
myMessage.bccEmail = @"zgsh0916@126.com";//抄送
myMessage.bccEmail = @"zgsh0916@gmail.com";
myMessage.bccEmail = @"957027534@qq.com";
myMessage.relayHost = @"smtp.exmail.qq.com";//發(fā)送地址host 騰訊企業(yè)郵箱:smtp.exmail.qq.com
myMessage.requiresAuth = YES;
myMessage.login = @"service@wiikang.com";//發(fā)送郵箱的用戶名
myMessage.pass = @"Wk_189";//發(fā)送郵箱的密碼
myMessage.wantsSecure = YES;
myMessage.subject = @"小優(yōu)健康管理平臺";//郵件主題
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];
});
}
**
發(fā)送成功回調(diào)
**
- (void)messageSent:(SKPSMTPMessage *)message
{
[MBProgressHUD showSuccess:@"郵件發(fā)送成功"];
WMLog(@"郵件發(fā)送成功");
}
**
發(fā)送失敗回調(diào)
**
- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
[MBProgressHUD showError:@"郵箱發(fā)送失敗,請檢查您的網(wǎng)絡(luò)是否正常"];
}
**
注意:用戶注冊為新浪郵箱時會造成崩潰旬盯,網(wǎng)上找了很多資料翎猛,沒有發(fā)現(xiàn)解決辦法接剩,反正國外的用戶用新浪的應(yīng)該比較少吧,就沒管它了
**