Skip to content

Patch: Mail add SSL Mode #70

@gonboy

Description

@gonboy

compare to: *Latest commit e3d01b1 * (2016-6-16)

application.ini
add
#0= TCP, 1= SSL

ActionMailer.smtp.Mode=1

tfnamespace.h
add
line183:

ActionMailerSmtpMode,

tappsettings.cpp
add
line67:

insert(Tf::ActionMailerSmtpMode, "ActionMailer.smtp.Mode");

tsmtpmailer.h
add

public:
    enum ConnectionType
    {
        TcpConnection=0,
        SslConnection=1,
        TlsConnection=2       // STARTTLS
    };

private:
    ConnectionType connectionType;

line27:
add

void setSmtpMode(int type);

tsmtpmailer.cpp

line35:
change:

TSmtpMailer::TSmtpMailer(QObject *parent)
    : QObject(parent), smtpPort(0), authEnable(false), pop(0)
{ }

change:

TSmtpMailer::TSmtpMailer(const QString &hostName, quint16 port, QObject *parent)
    : QObject(parent), smtpHostName(hostName), smtpPort(port),
      authEnable(false), pop(0)
{ }

add:

void TSmtpMailer::setSmtpMode(int type)
{
    if(type == (int)ConnectionType::TcpConnection) //tcp
    {
        connectionType = ConnectionType::TcpConnection;
        socket = new QTcpSocket;
    }
    else if(type == (int)ConnectionType::SslConnection)
    {
        connectionType = ConnectionType::SslConnection;
        socket = new QSslSocket;
    }
    else if(type == (int)ConnectionType::TlsConnection)
    {
        connectionType = ConnectionType::TlsConnection;
        socket = new QSslSocket;
    }
}

change:

bool TSmtpMailer::connectToHost(const QString &hostName, quint16 port)
{
//comment
//  socket->connectToHost(hostName, port);
//add
    switch (connectionType)
    {
    case TlsConnection:
    case TcpConnection:
        socket->connectToHost(hostName, port);
        break;
    case SslConnection:
        ((QSslSocket*) socket)->connectToHostEncrypted(hostName, port);
        break;
    }


    if (!socket->waitForConnected(5000)) {
        tSystemError("SMTP server connect error: %s", qPrintable(socket->errorString()));
        return false;
    }
    return (read() == 220);
}

tactionmailer.cpp
line77:
add

        mailer->setSmtpMode(Tf::appSettings()->value(Tf::ActionMailerSmtpMode).toUInt()));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions