bluetiger9 / SmtpClient-for-Qt

An SMTP Client writen in C++ for Qt. Allows applications to send emails (MIME with text, html, attachments, inline files, etc.) via SMTP. Supports SSL and SMTP authentication.
https://github.com/bluetiger9/SmtpClient-for-Qt/wiki
GNU Lesser General Public License v2.1
456 stars 227 forks source link

repeat send failed! #154

Closed liurunjieuk closed 6 months ago

liurunjieuk commented 6 months ago

repeat send failed!

/*
  Copyright (c) 2011 - Tőkés Attila

  This file is part of SmtpClient for Qt.

  SmtpClient for Qt is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 2 of the License, or
  (at your option) any later version.

  SmtpClient for Qt is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY.

  See the LICENSE file for more details.
*/

#include <QtCore>

#include "../SMTPEmail/SmtpMime"
#include "demo_vars.h"

int main(int argc, char* argv[]) {
    QCoreApplication app(argc, argv);

    // Create a MimeMessage

    MimeMessage message;

    EmailAddress sender(SENDER_EMAIL, SENDER_NAME);
    message.setSender(sender);

    EmailAddress to(RECIPIENT_EMAIL, RECIPIENT_NAME);
    message.addRecipient(to);

    message.setSubject(" Qt - Html email");

    // Now we need to create a MimeHtml object for HTML content
    MimeHtml html;

    html.setHtml("<table border=\"1\" style=\"border-collapse: collapse;\">"
                 "<tr>"
                 "<th style=\"padding: 10px;\">Header 1</th>"
                 "<th style=\"padding: 10px;\">Header 2</th>"
                 "</tr>"
                 "<tr>"
                 "<td style=\"padding: 10px;\">Data 1</td>"
                 "<td style=\"padding: 10px;\">Data 2</td>"
                 "</tr>"
                 "</table>");

    message.addPart(&html);

    // Now we can send the mail
    SmtpClient smtp(SMTP_SERVER, 465, SmtpClient::SslConnection);

    smtp.connectToHost();
    if (!smtp.waitForReadyConnected()) {
        qDebug() << "Failed to connect to host!";
        return -1;
    }

    smtp.login(SENDER_EMAIL, SENDER_PASSWORD);
    if (!smtp.waitForAuthenticated()) {
        qDebug() << "Failed to login!";
        return -2;
    }

    smtp.sendMail(message);
    if (!smtp.waitForMailSent()) {
        qDebug() << "Failed to send mail!";
        return -3;
    }
    smtp.quit();
    return 0;
}

and this is output


18:06:17: Starting D:\smtp-email\demo4\debug\demo4.exe...
SetProcessEncType<0>
[SmtpClient] State: ConnectingState
[Socket] State: QAbstractSocket::HostLookupState
[Socket] State: QAbstractSocket::ConnectingState
[Socket] State: QAbstractSocket::ConnectedState
[SmtpClient] State: ConnectedState
[Socket] IN:  "220 smtp.aliyun-inc.com MX AliMail Server\r\n"
[SmtpClient] State: _EHLO_State
[Socket] OUT: "EHLO localhost"
[Socket] IN:  "250-smtp.aliyun-inc.com\r\n"
[Socket] IN:  "250-8BITMIME\r\n"
[Socket] IN:  "250-AUTH=PLAIN LOGIN XALIOAUTH\r\n"
[Socket] IN:  "250-AUTH PLAIN LOGIN XALIOAUTH\r\n"
[Socket] IN:  "250-PIPELINING\r\n"
[Socket] IN:  "250 DSN\r\n"
[SmtpClient] State: _READY_Connected
[SmtpClient] State: ReadyState
[SmtpClient] State: AuthenticatingState
[SmtpClient] State: _AUTH_LOGIN_0
[Socket] OUT: "AUTH LOGIN"
[Socket] IN:  "334 dXNlcm5hbWU6\r\n"
[SmtpClient] State: _AUTH_LOGIN_1_USER
[Socket] OUT: "bGl1cnVuamllQGRlZXB3YXkuYWk="
[Socket] IN:  "334 UGFzc3dvcmQ6\r\n"
[SmtpClient] State: _AUTH_LOGIN_2_PASS
[Socket] OUT: "Y3N1c3RCNjA2"
[Socket] IN:  "235 Authentication successful\r\n"
[SmtpClient] State: _READY_Authenticated
[SmtpClient] State: ReadyState
[SmtpClient] State: MailSendingState
[SmtpClient] State: _MAIL_0_FROM
[Socket] OUT: "MAIL FROM:<liurunjie@deepway.ai>"
[Socket] IN:  "250 Mail Ok\r\n"
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[Socket] OUT: "RCPT TO:<deepcan@deepway.ai>"
[Socket] IN:  "250 Rcpt Ok\r\n"
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_3_DATA
[Socket] OUT: "DATA"
[Socket] IN:  "354 End data with <CR><LF>.<CR><LF>\r\n"
[SmtpClient] State: _MAIL_4_SEND_DATA
[Socket] OUT:
"From: liurunjie <liurunjie@deepway.ai>\r\nTo: deepcan <deepcan@deepway.ai>\r\nSubject:   Qt - Html email\r\nMIME-Version: 1.0\r\nContent-Type: multipart/related; boundary=8bb6c17838643f9691cc6a4de6c51709\r\nContent-Transfer-Encoding: 8bit\r\n\r\n--8bb6c17838643f9691cc6a4de6c51709\r\nContent-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\n\uFEFF<table border=\"1\" style=\"border-collapse: collapse;\"><tr><th style=\"padding: 10px;\">Header 1</th><th style=\"padding: 10px;\">Header 2</th></tr><tr><td style=\"padding: 10px;\">Data 1</td><td style=\"padding: 10px;\">Data 2</td></tr></table>\r\n--8bb6c17838643f9691cc6a4de6c51709--\r\n"
[Socket] OUT: "\r\n."
[Socket] IN:  "250 Data Ok: queued as freedom\r\n"
[SmtpClient] State: _READY_MailSent
[SmtpClient] State: ReadyState
[SmtpClient] State: _QUITTING_State
[Socket] OUT: "QUIT"
[Socket] IN:  "221 Bye\r\n"
[SmtpClient] State: DisconnectingState
[Socket] State: QAbstractSocket::ClosingState
[Socket] State: QAbstractSocket::ClosingState
[Socket] State: QAbstractSocket::UnconnectedState
[SmtpClient] State: UnconnectedState
waitForDisconnected result =  true
18:06:33: D:\DeepCan\smtp-email\demo4\debug\demo4.exe 崩溃。

18:06:56: Starting D:\DeepCan\smtp-email\demo4\debug\demo4.exe...
SetProcessEncType<0>
[SmtpClient] State: ConnectingState
[Socket] State: QAbstractSocket::HostLookupState
[Socket] State: QAbstractSocket::ConnectingState
[Socket] State: QAbstractSocket::ConnectedState
[SmtpClient] State: ConnectedState
[Socket] IN:  "220 smtp.aliyun-inc.com MX AliMail Server\r\n"
[SmtpClient] State: _EHLO_State
[Socket] OUT: "EHLO localhost"
[Socket] IN:  "250-smtp.aliyun-inc.com\r\n"
[Socket] IN:  "250-8BITMIME\r\n"
[Socket] IN:  "250-AUTH=PLAIN LOGIN XALIOAUTH\r\n"
[Socket] IN:  "250-AUTH PLAIN LOGIN XALIOAUTH\r\n"
[Socket] IN:  "250-PIPELINING\r\n"
[Socket] IN:  "250 DSN\r\n"
[SmtpClient] State: _READY_Connected
[SmtpClient] State: ReadyState
[SmtpClient] State: AuthenticatingState
[SmtpClient] State: _AUTH_LOGIN_0
[Socket] OUT: "AUTH LOGIN"
[Socket] IN:  "334 dXNlcm5hbWU6\r\n"
[SmtpClient] State: _AUTH_LOGIN_1_USER
[Socket] OUT: "bGl1cnVuamllQGRlZXB3YXkuYWk="
[Socket] IN:  "334 UGFzc3dvcmQ6\r\n"
[SmtpClient] State: _AUTH_LOGIN_2_PASS
[Socket] OUT: "Y3N1c3RCNjA2"
[Socket] IN:  "235 Authentication successful\r\n"
[SmtpClient] State: _READY_Authenticated
[SmtpClient] State: ReadyState
[SmtpClient] State: MailSendingState
[SmtpClient] State: _MAIL_0_FROM
[Socket] OUT: "MAIL FROM:<liurunjie@deepway.ai>"
[Socket] IN:  "250 Mail Ok\r\n"
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[Socket] OUT: "RCPT TO:<deepcan@deepway.ai>"
[Socket] IN:  "250 Rcpt Ok\r\n"
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_2_RCPT
[SmtpClient] State: _MAIL_1_RCPT_INIT
[SmtpClient] State: _MAIL_3_DATA
[Socket] OUT: "DATA"
[Socket] IN:  "354 End data with <CR><LF>.<CR><LF>\r\n"
[SmtpClient] State: _MAIL_4_SEND_DATA
[Socket] OUT:
"From: liurunjie <liurunjie@deepway.ai>\r\nTo: deepcan <deepcan@deepway.ai>\r\nSubject:   Qt - Html email\r\nMIME-Version: 1.0\r\nContent-Type: multipart/related; boundary=05d85804dd3e689e1f1a0aaa1975fb4c\r\nContent-Transfer-Encoding: 8bit\r\n\r\n--05d85804dd3e689e1f1a0aaa1975fb4c\r\nContent-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\n\uFEFF<table border=\"1\" style=\"border-collapse: collapse;\"><tr><th style=\"padding: 10px;\">Header 1</th><th style=\"padding: 10px;\">Header 2</th></tr><tr><td style=\"padding: 10px;\">Data 1</td><td style=\"padding: 10px;\">Data 2</td></tr></table>\r\n--05d85804dd3e689e1f1a0aaa1975fb4c--\r\n"
[Socket] OUT: "\r\n."
[Socket] IN:  "250 Data Ok: queued as freedom\r\n"
[SmtpClient] State: _READY_MailSent
[SmtpClient] State: ReadyState
[SmtpClient] State: _QUITTING_State
[Socket] OUT: "QUIT"
attila-tokes commented 6 months ago

@liurunjieuk, what is wrong here? 🙂 Too me it looks both attempts were successfully acknowledged with 250 Data Ok by the server.

liurunjieuk commented 6 months ago

i

@liurunjieuk, what is wrong here? 🙂 Too me it looks both attempts were successfully acknowledged with 250 Data Ok by the server.

The first email was successfully sent, but subsequent emails sent immediately afterward were not received in the mailbox.

attila-tokes commented 6 months ago

Hmm, maybe you're hitting some spam / other filtering on the mail server side. I would suggest contacting the mail provider.

The mail server accepts both of your messages for queueing, so on the library side is not much we can do...

liurunjieuk commented 6 months ago

Hmm, maybe you're hitting some spam / other filtering on the mail server side. I would suggest contacting the mail provider.

The mail server accepts both of your messages for queueing, so on the library side is not much we can do...

Dear,this git@github.com:cutelyst/simple-mail.git is ok

liurunjieuk commented 6 months ago

@attila-tokes Dear,my connection is TLS ,and there is no 'STARTTLS' cmd in the progress

liurunjieuk commented 6 months ago

@attila-tokes Dear, I don't have permission,please add code in the minemessage.cpp,branch v2.0 Fix repeat send email failed!

/* ------------ DATE ------------- */

    header.append("Date: ");
    header.append(QDateTime::currentDateTime().toString(Qt::RFC2822Date));
    header.append("\r\n");
    /* ---------------------------------- */