Commit 0083eea5 authored by Jan Kundrát's avatar Jan Kundrát
Browse files

Untested attempt at sending mails via SMTP

parent 888f916f
......@@ -92,6 +92,7 @@ set(libStreams_SRCS
set(libMSA_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/MSA/AbstractMSA.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MSA/Sendmail.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MSA/SMTP.cpp
)
set(trojita_SRCS
......
......@@ -15,6 +15,7 @@
#include "SettingsNames.h"
#include "RecipientsWidget.h"
#include "MSA/Sendmail.h"
#include "MSA/SMTP.h"
#include "Imap/Parser/3rdparty/kmime_util.h"
......@@ -62,8 +63,12 @@ void ComposeWidget::send()
QSettings s;
MSA::AbstractMSA* msa = 0;
if ( s.value( SettingsNames::msaMethodKey ).toString() == SettingsNames::methodSMTP ) {
qFatal( "SMTP not implemented yet, sorry" );
return;
msa = new MSA::SMTP( this, s.value( SettingsNames::smtpHostKey ).toString(),
s.value( SettingsNames::smtpPortKey ).toInt(),
false, false, // FIXME: encryption & startTls
s.value( SettingsNames::smtpAuthKey ).toBool(),
s.value( SettingsNames::smtpUserKey ).toString(),
s.value( SettingsNames::smtpPassKey ).toString() );
} else {
QStringList args = s.value( SettingsNames::sendmailKey, SettingsNames::sendmailDefaultCmd ).toString().split( QLatin1Char(' ') );
Q_ASSERT( ! args.isEmpty() ); // FIXME
......
#include "SMTP.h"
namespace MSA {
SMTP::SMTP( QObject* parent, const QString& host, quint16 port,
bool encryptedConnect, bool startTls, bool auth,
const QString& user, const QString& pass ):
AbstractMSA(parent), _host(host), _port(port),
_encryptedConnect(encryptedConnect), _startTls(startTls), _auth(auth),
_user(user), _pass(pass)
{
_qwwSmtp = new QwwSmtpClient( this );
// FIXME: handle SSL errors properly
connect( _qwwSmtp, SIGNAL(sslErrors(QList<QSslError>)), _qwwSmtp, SLOT(ignoreSslErrors()) );
connect( _qwwSmtp, SIGNAL(connected()), this, SIGNAL(sending()) );
connect( _qwwSmtp, SIGNAL(done(bool)), this, SLOT(handleDone(bool)) );
}
void SMTP::cancel()
{
_qwwSmtp->disconnectFromHost();
}
void SMTP::handleDone( bool ok )
{
qDebug() << "handleDone" << ok;
if ( ok )
emit sent();
else
emit error( "blesmrt" );
}
void SMTP::sendMail( const QStringList& to, const QByteArray& data )
{
emit progressMax( data.size() );
emit progress( 0 );
emit connecting();
if ( _encryptedConnect )
_qwwSmtp->connectToHostEncrypted( _host, _port );
else
_qwwSmtp->connectToHost( _host, _port );
if ( _startTls )
_qwwSmtp->startTls();
if ( _auth )
_qwwSmtp->authenticate( _user, _pass );
emit sending(); // FIXME: later
_qwwSmtp->sendMail( /*FIXME*/ "kundratj@fzu.cz", to, data );
_qwwSmtp->disconnectFromHost();
}
}
#include "SMTP.moc"
#ifndef SMTP_H
#define SMTP_H
#include "AbstractMSA.h"
#include "qwwsmtpclient/qwwsmtpclient.h"
namespace MSA {
class SMTP : public AbstractMSA
{
Q_OBJECT
public:
SMTP( QObject* parent, const QString& host, quint16 port,
bool encryptedConnect, bool startTls, bool auth,
const QString& user, const QString& pass );
virtual void sendMail( const QStringList& to, const QByteArray& data );
public slots:
virtual void cancel();
void handleDone( bool ok );
private:
QwwSmtpClient* _qwwSmtp;
QString _host;
quint16 _port;
bool _encryptedConnect;
bool _startTls;
bool _auth;
QString _user;
QString _pass;
};
}
#endif // SMTP_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment