QT SMTP send mail (encapsulation Library)

         SMTP is a set of rules used to deliver mail from source address to destination address, and controls the transit mode of mail. SMTP protocol It belongs to the TCP/IP protocol family. It helps each computer find the next destination when sending or forwarding letters. Through the server specified by SMTP protocol, we can send E-mail to the recipient's server. The whole process takes only a few minutes. The SMTP server follows the SMTP protocol Mail server Used to send or relay e-mail sent by users.

     The author of this article is original. For reprint, please attach the source of the article and the link to this article.

        The source of the program is temporarily closed, but it is free, and the version will be updated all the time. At present, it is in the testing stage. The first email and functions have been realized, and other more personalized functions will be updated one after another.

        This paper is divided into two parts, one is the project description, one is the test project, and the other is part of the open source code.

QT SMTP send mail (encapsulation Library) directory

1. Project description

2. Test items

2.1 screenshot of test software

  2.2 partial source code

3. Partial source code

4. Resource file

1. Project description

        The software supports 126, 139, QQ, Alibaba and other mainstream mailboxes

        The software supports sending mail by TcpConnection, SslConnection and TlsConnection

        The next update goal of the software is to update and build attachments by the end of October 2021 to provide the function of sending attachments

         The next update goal of the software is to update the customized content of the sent mail, including font color, format, and other free personalized settings by the end of November 2021

        If you find any problems during use, please leave a message and it will be updated and solved in time.

2. Test items

2.1 screenshot of test software

  2.2 partial source code

.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include "qt_email_dll.h"
#include "QT_Email_Dll_global.h"

#pragma execution_character_set("utf-8")
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();


private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    int ierrorCode = 0;
    QString strText ="";

    QT_Email_Dll Q_EmailDll;

   //strText = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$";
    strText = "[a-zA-Z0-9-_|a-zA-Z\.vip]+@[a-zA-Z0-9-_]+\\.[a-zA-Z]+";


   ierrorCode = Q_EmailDll.OnInitDialog("xxxxx@qq.com","xxxxxpw","xxxxx@qq.com","xxxxx","xxxxx@qq.com","xxxxx",ui->textEdit->toPlainText(),strText);
   if(ierrorCode != 0)
   {
       qDebug() << "Parameter error" << ierrorCode;
       return;
   }
   ierrorCode = Q_EmailDll.InitDreamBeginsEmail("smtp.qq.com",587,0);
   if(ierrorCode != 0)
   {
       qDebug() << " code error"<< ierrorCode;
       return;
   }
   qDebug() << " Email Successful" ;
}

3. Partial source code

    /**
     *  @fn     OnInitDialog(QString EName, QString EPwd, QString ESender, QString ESenderName, QString ERecipient, QString ETitle, QString ETextData)
     *  @brief  Initialize Input Parameters
     *  @param  EName       [IN]    - Server EmailName
                EPwd        [IN]    - Server EamilPassword
                ESender     [IN]    - The    Sender
                ESenderName [IN]    - The    Sender Email
                ERecipient  [IN]    - The    Recipient
                ETitle      [IN]    - Email  Title
                ETextData   [IN]    - Email  Content
                ERegExp     [IN]    - Email  Rules
     *  @return return Success 0; Fail, return Error Srever -1; return Error UserLogin -2; return Error EmailSend -3;
     */
    int OnInitDialog(QString EName, QString EPwd, QString ESender, QString ESenderName, QString ERecipient, QString ETitle, QString ETextData, QString ERegExp);

    /**
     *  @fn     InitDreamBeginsEmail(QString strEmail, int iPort, int Connection)
     *  @brief  Initialization Parameter Connection Email
     *  @param  strEmail     [IN]    - Server       smtp.qq.com  smtp.163.com    smtp.126.com    smt.sina.com    smtp.sohu.com   smtp.139.com    smtp.189.com
                iPort        [IN]    - Port         25           465             587
                Connection   [IN]    - connection   0 TcpConnection     1 SslConnection     2 TlsConnection
     *  @return return Success 0; Fail, return Error Srever -1; return Error UserLogin -2; return Error EmailSend -3;
     */
    int InitDreamBeginsEmail(QString strEmail, int iPort, int Connection);

    /**
     *  @fn     Validation(QString QStr, QString RegExp)
     *  @brief  Email Check
     *  @param  QStr         [IN]    - Email
     *  @param  RegExp       [IN]    - ValidationRules
     *  @return return Correct 0; return Error 1;
     */
    int Validation(QString QStr, QString RegExp);

4. Resource file

Full test item address:

https://download.csdn.net/download/qq_37529913/24092280

Dependent file download:

https://download.csdn.net/download/qq_37529913/24093884

 

Tags: Qt html

Posted on Tue, 21 Sep 2021 13:35:22 -0400 by Lustre