Qt World Summit: Register Today!

Send mail

  • Hello,
    I have downloaded libqxt, and make this. But I have no idea how to use this for sending mail.

  • Lifetime Qt Champion


    From a quick look at the doc:


    And the third result from a google search with QxtSmtp example as key words gives a pretty complete example.

  • I used git clone https://bitbucket.org/libqxt/libqxt.git for download source code,

    I run this commands :

    -configure -debug_and_release
    -mingw32-make install

    it's works

    but when i compile, i get a message for dynamic links :

    _imp___ZN7QxtSmtpC1EP7QObject ...

    .pro :

    QT+= network
    QXT+= core gui 
    LIBS+=-LB:/etudes/Programmationastuce/Qt/Bibliotheque/libqxt/lib/ -lQxtCore
    INCLUDEPATH += B:/etudes/Programmationastuce/Qt/Bibliotheque/libqxt/include/QxtCore \

  • Lifetime Qt Champion

    QxtSmtp is is the network module of Qxt not of Qt.

  • Same error.
    After mingw32-make install

  • Lifetime Qt Champion

    Doesn0t look like the same thing. You seem to have errors with Qxt itself or am I misunderstanding ?

  • Yes, I have a problem with Qxt, I included the path in variable environments

  • Lifetime Qt Champion

    Did you check the pull request to make it buildable with Qt 5 ?

    If not the most simple course of action (and the one the folks behind the library suggests) is to copy the sources of the classes you need in your project.

  • I remove all files except qxtglobal., qxtmailmessage, qxtmailattachment .h and .cpp

    i get same error :
    alt text

  • Lifetime Qt Champion

    I didn't suggest to delete anything in libqxt.

    What I suggested, based on what the authors of the library wrote, is that you copy the files you need inside your project and build them as part of your project.

  • @SGaist Doesn't work, with compile
    alt text

    and with copy direct in my project, I get a problem with an old version of Qt


    alt text

  • Lifetime Qt Champion

    What does the .pro file of your test project look like ?

  • alt text

    i tried in ubuntu, but always error

  • Lifetime Qt Champion

    TEMPLATE = app
    TARGET = test_email
    QT += network
    # Input
    HEADERS += qxtglobal.h \
               qxtmail_p.h \
               qxtmailattachment.h \
               qxtmailmessage.h \
               qxtsmtp.h \
               qxtsmtp_p.h \
    SOURCES += main.cpp \
               qxtglobal.cpp \
               qxtmailattachment.cpp \
               qxtmailmessage.cpp \
               qxtsmtp.cpp \

    Is what I have and it's building except I needed to add a forward declaration for QIODevice in qxtmailattachement.h

  • I copied direct, no make , same error in release and debug mode
    alt text

    But why i get this message after execution of mingw32-make ?

    alt text

    I followed this guide https://bitbucket.org/libqxt/libqxt/wiki/user_guidet

  • Lifetime Qt Champion

    Did you do a clean rebuild ?

    As for the second error, you took the original sources which were written for Qt 4. There has been some changes with Qt 5 so if you want to build Qxt with Qt 5. As I wrote before, you should at least take a look at the pull request related to that.

  • Thaaank, it finally compile, I take the pull request, and i add a #include <QIODevice> in file QxtMailAttachement.h .

    but he remain a last problem .


    TEMPLATE = app
    TARGET = test_email
    CONFIG  += qxt
    QXT += core
    QT += network
    # Input
    SOURCES += main.cpp 
    INCLUDEPATH+= C:/Qxt/include
    LIBS+= -LC:/Qxt/bin -lQxtCored -lQxtNetworkd -lQxtSqld -lQxtWebd -lQxtWidgetsd


    #include <QtCore>
    #include <QtGui>
    #include <QxtMailMessage>
    #include <QxtSmtp>
    #include <QtNetwork>
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QxtMailMessage message;
        message.setBody("Alarm message.");
        QxtSmtp smtp;
        a.connect(&smtp, SIGNAL(mailSent(int)), SLOT(quit()));
        return a.exec();

    I wanted to send an email, but it does not send, and same problem with hotmail.

  • Lifetime Qt Champion

    You should add some error handling, there are several things that could go wrong.

    testSmtp::testSmtp(QWidget *parent) : QWidget(parent)
          QxtMailMessage *message =new QxtMailMessage;;
          message->setBody("Alarm message.");
          QxtSmtp *smtp= new QxtSmtp(this);
           connect(smtp, SIGNAL(mailSent(int)), this, SLOT(mailSent(int)));
           connect(smtp, SIGNAL(mailFailed(int,int,QByteArray)), this, SLOT(mailFailed(int,int,QByteArray)));
           connect(smtp, SIGNAL(recipientRejected(int,QString,QByteArray)), this, SLOT(recipientRejected(int,QString,QByteArray)));
           connect(smtp, SIGNAL(senderRejected(int,QString,QByteArray)), this, SLOT(senderRejected(int,QString,QByteArray)));
           connect(smtp, SIGNAL(connected()), this, SLOT(connected()));
           connect(smtp, SIGNAL(connectionFailed(QByteArray)), this, SLOT(connectionFailed(QByteArray)));
           connect(smtp, SIGNAL(authenticated()), this, SLOT(authenticated()));
           connect(smtp, SIGNAL(authenticationFailed(QByteArray)), this, SLOT(authenticationFailed(QByteArray)));
           connect(smtp, SIGNAL(finished()), this, SIGNAL(finished()));
    void testSmtp::mailSent(int mailID){
        qDebug() << mailID << true;
        emit finished(mailID, true);
    void testSmtp::mailFailed(int mailID, int, const QByteArray & msg){
        emit finished(mailID, false);
        emit erreur(QString::number(mailID) + " mailFailed " + msg, __LINE__);
    void testSmtp::recipientRejected(int mailID, const QString& address, const QByteArray & msg  ){
        emit erreur(QString::number(mailID) + "recipientRejected " + address + " " + msg, __LINE__);
    void testSmtp::senderRejected(int mailID, const QString& address, const QByteArray & msg  ){
        emit erreur(QString::number(mailID) + "senderRejected " + address + " " + msg, __LINE__);
    void testSmtp::connected(){
            qDebug() << "connected";
    void testSmtp::connectionFailed( const QByteArray & msg ){
        emit erreur("connectionFailed " + msg, __LINE__);
    void testSmtp::authenticated(){
            qDebug() << "authenticated";
    void testSmtp::authenticationFailed( const QByteArray & msg ){
        emit erreur("authenticationFailed " + msg, __LINE__);


    class testSmtp : public QWidget
        explicit testSmtp(QWidget *parent = 0);
    public slots:
        void mailSent(int mailID);
         void mailFailed(int mailID, int, const QByteArray & msg);
         void recipientRejected(int mailID, const QString & address, const QByteArray & msg );
         void senderRejected(int mailID, const QString & address, const QByteArray & msg );
         void connected();
         void connectionFailed( const QByteArray & msg );
         void authenticated();
         void authenticationFailed( const QByteArray & msg );
        void finished();
        void finished(int id, bool result);
        void erreur(QString text, int no_ligne);

    i have no error . but it doesn't send

  • Lifetime Qt Champion

    Don't send the message before connecting all the signals.

    Add a button and in the slot connected to its clicked signal, create and send the message.

  • I tried, but always Nothing, when i click in button, no message error .

     QPushButton *button = new QPushButton("Send",this);
          QxtMailMessage *message =new QxtMailMessage;;
          QxtSmtp *smtp= new QxtSmtp(this);
               message->setBody("Alarm message.");
    /*other signal*/

    I also tried to write functions of QXtSmtp in the slot lamba-function but nothing

  • Did you turned on less secure apps?

  • Yes, i used this code source : https://codeload.github.com/xcoder123/SimpleSmtp_SSL_QT5/zip/master and he works perfectly .

  • The essential Qxt is builded and works.
    @SGaist thank you for your help :)

Log in to reply