开发者社区> 问答> 正文

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

登陆账号已经是邮箱全名,端口号25,服务器域名是smtp.mxhichina.com,还是有问题。。。

展开
收起
小葛物联 2016-01-22 08:43:08 17900 0
3 条回答
写回答
取消 提交回答
  • 2020-11-24 15:58:11
    赞同 展开评论 打赏
  • 我也遇到这样的问题,可能是你用的管理员的账号,必须用新建的其他账号才能使用程序发送成功

    2019-11-27 10:02:30
    赞同 1 展开评论 打赏
  • 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:<%s>\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:<%s>\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;

    }

    2019-07-17 18:26:00
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载