PDA

View Full Version : Getting CONNREFUSED error while sending mail using RWSmtpClient



cagespear
06-27-2008, 03:23 AM
I am using RWSmtpclient to send mails to the user. It works fine 99% of the time. But lately, some users are sporadically getting the below errors

RWSocketError: in RWSocket::connect::CONNREFUSED

I am using the same code as what the API suggests -

***********************************************

RWSmtpClient client; // SMTP client object
RWSmtpReply reply; // SMTP general reply
RWSmtpDataReply dReply; // SMTP data reply

try {
// Connect to our SMTP server
reply = client.connect("smtp.roguewave.com");

// Say hello from the local machine
reply = client.helo("tsunami");

// Mail From: and To:
reply = client.mail("customer.roguewave.com");
reply = client.rcpt("support.roguewave.com");

// Send a help message
dReply = client.dataOpen();
dReply.portal().sendAtLeast("We've got a problem... \n");
dReply.portal().sendAtLeast("Please help immediately");

// Indicate it's the end of the message
reply = client.dataClose();

// Send more messages, if you like

// Finally shut down the connection
reply = client.quit();
}
catch (const RWxmsg& m) {
cout << "Error : " << m.why() << endl;

***********************************************

Its seems to me that smtp server refused the connection in this case. But the question is Why ? The same user who reported this error *is* still able to send mails but sometimes this error comes.

The other qn is - what should be the right approach to handle such errors ? Should I try to re-send the mail in such case ? Or print some more logs for debugging purpose ?

Thanks
cage

bgomez
07-08-2008, 11:26 AM
I couldn't find any wording in the SMTP or TCP standards that describes appropriate behavior when encountering this kind of situation. As far as using the SMTP client, there is always a possibility that a connection may fail for some reason.

If the connection fails, the best approach is to retry the connection and then proceed with sending the mail.

johannt
07-31-2008, 11:33 AM
I have been getting similar issues with a client (c#) to server(rw c++) application using sockets. We are unable to reproduce the error but it occurs in production every 10.000 to 15.000 calls. We have not seen this to be stress related.
If we find anything new I'll post a new message.