Important: Please read the Qt Code of Conduct -

[Solved]SMTP Authentification

  • Hi
    I have tried this prj in my app but I don't get it to work properly

    I dont. get the mail to be sent in that code,

    Then I have an other code to send mail via SMTP and the main part looks like this
    @SmtpClient::SmtpClient( const QString &from, const QString &to, const QString &subject, const QString &body )
    socket = new QTcpSocket( this );
    connect( socket, SIGNAL(readyRead()), this, SLOT( readyRead() ) );

    connect( socket, SIGNAL( connected() ), this, SLOT( connected() ) );
    connect( socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
    connect( socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this,
    connect(socket, SIGNAL(disconnected()), this,

    message = "To: " + to + "\n";
    message.append("From: " + from + "\n");
    message.append("Subject: " + subject + "\n");
    message.append("\r\n" + body);
    message.replace( QString::fromLatin1( "\n" ), QString::fromLatin1( "\r\n" ) );
    message.replace( QString::fromLatin1( "\r\n.\r\n" ),

    QString::fromLatin1( "\r\n..\r\n" ) );
    this->from = from;
    rcpt = to;
    state = Init;
    //this->Maddress = to.mid( to.indexOf('@',1)+1);

    //QString s= "smtp.";
    socket->connectToHost( "" , 25);

    if(socket->waitForConnected ( 40000 )) {qDebug("connected"); }

    t = new QTextStream( socket );
    and so on......

    But in this code I'm not sure how to set Authentification to the mailserver when so is needed:

    Is there a simpler way to solve this problem with smtp and mail in qt.
    I have been looking around but I always end up with this two examples

  • Looks OK
    Have you used it.

  • No, I haven't, but LibQxt extension is not bad at all, should actually work.

  • Worked perfect for me.

  • Hello,

    socket = new QSslSocket(this);

    this line generate a error like "Illegal Instruction";
    i use qt4.6.3 version for ARM baord please help me

Log in to reply