{
const int Timeout = 5 * 1000;
linesend = 0;
qDebug() << "### Launch mail compose.... " << from << to << subject << body;
qDebug() << "### Config server smtp connect to...... " << smtphost;
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 ";
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();
}
}
}
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();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks