Originally Posted by
wysota
Looks like the DNS works correctly then. Could you provide a minimal compilable example reproducing the problem?
As I told I have copied the same code available in qtassistant in qt3. Anyway here is the link
http://web.mit.edu/qt_v3.3.3/www/mail-example.html
Here is the code
{
socket = new QSocket( this );
connect ( socket, SIGNAL( readyRead() ),
this, SLOT( readyRead() ) );
connect ( socket, SIGNAL( connected() ),
this, SLOT( connected() ) );
connect ( socket, SIGNAL( error ( int ) ),
this, SLOT( slotShowError(int) ) );
mxLookup = new QDns( to.mid( to.find( '@' )+1 ), QDns::Mx );
connect( mxLookup, SIGNAL(resultsReady()),
this, SLOT(dnsLookupHelper()) );
message
= QString::fromLatin1( "From: " ) + from
+ QString::fromLatin1( "\nTo: " ) + to
+ QString::fromLatin1( "\nSubject: " ) + subject
+ QString::fromLatin1( "\n\n" ) + body
+ "\n";
message.
replace( message,
QString::fromLatin1( "\n" ),
message.
replace( message,
QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
sender = from;
rcpt = to;
state = Init;
}
Smtp::Smtp( const QString &from, const QString &to,
const QString &subject,
const QString &body )
{
socket = new QSocket( this );
connect ( socket, SIGNAL( readyRead() ),
this, SLOT( readyRead() ) );
connect ( socket, SIGNAL( connected() ),
this, SLOT( connected() ) );
connect ( socket, SIGNAL( error ( int ) ),
this, SLOT( slotShowError(int) ) );
mxLookup = new QDns( to.mid( to.find( '@' )+1 ), QDns::Mx );
connect( mxLookup, SIGNAL(resultsReady()),
this, SLOT(dnsLookupHelper()) );
message = QString::fromLatin1( "From: " ) + from +
QString::fromLatin1( "\nTo: " ) + to +
QString::fromLatin1( "\nSubject: " ) + subject +
QString::fromLatin1( "\n\n" ) + body + "\n";
message.replace( message, QString::fromLatin1( "\n" ),
QString::fromLatin1( "\r\n" ) );
message.replace( message, QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
sender = from;
rcpt = to;
state = Init;
}
To copy to clipboard, switch view to plain text mode
void Smtp::dnsLookupHelper()
{
QValueList<QDns::MailServer> s = mxLookup->mailServers();
if ( s.isEmpty() && mxLookup->isWorking() )
{
emit status( tr( "Could not find mail server. Please check address." ) );
tr( "SynsupMail" ),
tr( "Could not find mail server for address:\n\n %1" ).arg( rcpt ) );
QTimer::singleShot( 0,
this,
SLOT(deleteMe
()) );
return;
}
emit status( tr( "Connecting to %1" ).arg( s.first().name ) );
socket->connectToHost( s.first().name, 25 ); //The error occurs here
}
void Smtp::dnsLookupHelper()
{
QValueList<QDns::MailServer> s = mxLookup->mailServers();
if ( s.isEmpty() && mxLookup->isWorking() )
{
emit status( tr( "Could not find mail server. Please check address." ) );
QMessageBox::warning( qApp->activeWindow(),
tr( "SynsupMail" ),
tr( "Could not find mail server for address:\n\n %1" ).arg( rcpt ) );
QTimer::singleShot( 0, this, SLOT(deleteMe()) );
return;
}
emit status( tr( "Connecting to %1" ).arg( s.first().name ) );
socket->connectToHost( s.first().name, 25 ); //The error occurs here
t = new QTextStream( socket );
}
To copy to clipboard, switch view to plain text mode
//The control never comes here
void Smtp::connected()
{
emit status( tr( "Connected to %1" ).arg( socket->peerName() ) );
}
//Displays error status as 0 which is QSocket::ErrConnectionRefused
void Smtp::slotShowError(int errorNo)
{
qDebug
("%Error:"+QString("%1").
arg((QSocket
::Error)errorNo
));
}
//The control never comes here
void Smtp::connected()
{
emit status( tr( "Connected to %1" ).arg( socket->peerName() ) );
}
//Displays error status as 0 which is QSocket::ErrConnectionRefused
void Smtp::slotShowError(int errorNo)
{
qDebug("%Error:"+QString("%1").arg((QSocket::Error)errorNo));
}
To copy to clipboard, switch view to plain text mode
Again the code is same as what is given in qtassistant( qt3 ).
Bookmarks