guanq429_个人页

个人头像照片 guanq429
个人头像照片
0
1
0

个人介绍

暂无个人介绍

擅长的技术

  • Java
  • Go
  • Linux
获得更多能力
通用技术能力:

暂时未有相关通用技术能力~

云产品技术能力:

暂时未有相关云产品技术能力~

阿里云技能认证

详细说明
暂无更多信息
暂无更多信息
正在加载, 请稍后...
暂无更多信息
  • 回答了问题 2019-07-17

    SMTP登陆阿里云免费邮箱526 Authentication failure[0]

    SMTP登陆阿里云企业免费邮箱端口25或者80,不能使用auth login的验证方式,只能使用auth plain的验证方式,贴段我成功发送邮件的代码,CreatSocket就不贴了bool CSendMail::PlainSend(SOCKET &sock){ memset(send_buff_, 0, sizeof(send_buff_)); sprintf_s(send_buff_, 'HELO %s\r\n', mail_info_.mail_server_ip_addr); send(sock, send_buff_, strlen(send_buff_), 0); // 开始会话 memset(receive_buff_, 0, sizeof(receive_buff_)); recv(sock, receive_buff_, 1024, 0); if (receive_buff_[0] != '2' || receive_buff_[1] != '5' || receive_buff_[2] != '0') return false; const char* user = mail_info_.mailbox_user_name; const char* pass = mail_info_.mailbox_user_pwd; char outstr[1024] = {}; char instr[1024] = {}; strcpy(instr, user); strcpy(instr + strlen(user) + 1, user); strcpy(instr + strlen(user) * 2 + 2, pass); Char2Base64(outstr, instr, strlen(user) * 2 + 2 + strlen(pass));//账户名和密码必须使用user\0user\0pass形式再encode memset(send_buff_, 0, sizeof(send_buff_)); sprintf_s(send_buff_, 'AUTH PLAIN %s\r\n', outstr);//阿里云企业邮只能用AUTH PLAIN,不能使用AUTH LOGIN,163邮都可以 send(sock, send_buff_, strlen(send_buff_), 0); memset(receive_buff_, 0, sizeof(receive_buff_)); recv(sock, receive_buff_, 1024, 0); if (receive_buff_[0] != '2' || receive_buff_[1] != '3' || receive_buff_[2] != '5')return false;// 登录成功 memset(send_buff_, 0, sizeof(send_buff_)); sprintf_s(send_buff_, 'MAIL FROM:\r\n', mail_info_.mailbox_sender); if (send(sock, send_buff_, strlen(send_buff_), 0) != strlen(send_buff_))return false; recv(sock, receive_buff_, 1024, 0); memset(send_buff_, 0, sizeof(send_buff_)); sprintf_s(send_buff_, 'RCPT TO:\r\n', mail_info_.mailbox_receiver); if (send(sock, send_buff_, strlen(send_buff_), 0) != strlen(send_buff_))return false; recv(sock, receive_buff_, 1024, 0); memset(send_buff_, 0, sizeof(send_buff_)); memcpy(send_buff_, 'DATA\r\n', strlen('DATA\r\n')); if (send(sock, send_buff_, strlen(send_buff_), 0) != strlen(send_buff_))return false; recv(sock, receive_buff_, 1024, 0); string datastr;//这个from,reply-to,to,timestr对阿里云企业邮箱都是必须的,否则可能收不到邮件 datastr += 'From: ' + string(mail_info_.mailbox_sender) + '\r\n' + 'Reply-To: ' + string(mail_info_.mailbox_sender) + '\r\n'; datastr += 'To: ' + string(mail_info_.mailbox_receiver) + '\r\n'; time_t t=time(NULL);char timestr[128]; strftime(timestr, 127, 'Date: %d %b %y %H:%M:%S', localtime(&t)); datastr += string(timestr) + '\r\n'; datastr += 'Subject: ' + string(mail_info_.mail_title) + '\r\n\r\n'; datastr += string(mail_info_.mail_body) + '\r\n'; datastr += '.\r\n'; send(sock, datastr.c_str(), datastr.length(), 0); recv(sock, receive_buff_, 1024, 0);//正常回复250 if (receive_buff_[0] != '2' || receive_buff_[1] != '5' || receive_buff_[2] != '0')return false; OutputDebugString(receive_buff_); sprintf_s(send_buff_, 'quit\r\n'); send(sock, send_buff_, strlen(send_buff_), 0); recv(sock, receive_buff_, 1024, 0); if (receive_buff_[0] != '2' || receive_buff_[1] != '2' || receive_buff_[2] != '1')return false; OutputDebugString(receive_buff_);//正常回复221,即使这样,如果DATA没加from,reply-to,to,timestr发送也经常不成功 closesocket(sock); WSACleanup(); return true; }
    踩0 评论0
正在加载, 请稍后...
滑动查看更多
正在加载, 请稍后...
暂无更多信息