PDA

View Full Version : How to create a CRAM-MD5 password on QT



patrik08
27th May 2006, 22:17
I have a smtp auth connection and is ready to read qt4...



now i send
1- ehlo localhost
-------server
250-remote.com
250-STARTTLS
250-PIPELINING
250-8BITMIME
250-SIZE 0
250 AUTH LOGIN PLAIN CRAM-MD5
-------server
2- auth user@domaine.com
3- 334 VXNlcm5hbWU6
-------server
235 authentication finished successfully
-------server
4- mail from: user@domaine.com
Data .....
and wait...
-------server
221 Bye
-------server

..... How to create a CRAM-MD5 password on QT?




Smtp::Smtp( const QString &from, const QString &to, const QString &subject, const QString &body )
{

const QString smtphost = "ppk.go";
const int Timeout = 5 * 1000;
linesend = 0;
qDebug() << "### Launch mail compose.... " << from << to << subject << body;
qDebug() << "### Config server smtp connect to...... " << smtphost;
smtpsocket = new QTcpSocket(this);
connect( this, SIGNAL(ConnectorSuccess()), this ,SLOT(ReadLiner()));
connect( this, SIGNAL(SendLine()), this ,SLOT(PutSendLine()));
smtpsocket->connectToHost(smtphost,25);
if (smtpsocket->waitForConnected(Timeout)) {
qDebug() <<"### connected on " << smtphost;
if (smtpsocket->waitForReadyRead(Timeout)) {
qDebug() <<"### emit from waitForReadyRead connect go can read";
emit ConnectorSuccess();
}
}

}

void Smtp::ReadLiner()
{
qDebug() << "### socketType = " << smtpsocket->socketType();
qDebug() << "### ReadLiner is start by textstream ";
t = new QTextStream( smtpsocket );
int loops = 0;
while (!t->atEnd()) {
loops++;
response = t->readLine();
qDebug() << loops << " in line " << response;
}
if (response.size() > 0) {
RemoteServerName = response;
mailstatus = response.left(3);
qDebug() << "###Status=" << mailstatus;
if (mailstatus == "220") {
linesend = 1;
emit SendLine();
}
}
}

jacek
27th May 2006, 22:37
Use QSA (http://www.qtcentre.org/index.php?option=com_weblinks&task=view&catid=23&id=22) or some other library.

jpn
28th May 2006, 00:45
AFAIR there's some public domain implementation of MD5 in 3rd party sources of Qt... Check src/3rdparty..

patrik08
28th May 2006, 01:37
I tested encodeBase64 and mail is going/send .... Postfix server....
auth ok ....

But now i muss format a date so...:confused: ??

message = "Date: Mon, 08 May 2006 17:57:52 +0200\n";

on php i make this date quikly ... on qt Cutedatetime...

class smtp auth have a look http://svn.sourceforge.net/viewcvs.cgi/qtexcel-xslt/smtp/



QString Smtp::encodeBase64( QString xml )
{
QByteArray text;
text.append(xml);
return text.toBase64();
}