I'm trying to send email using asp.net mvc application. Smtp client is configured in web.config e.g.:
<mailSettings>
<smtp from="noreply@test.sk">
<network host="mail.test.sk" defaultCredentials="false" userName="noreply@test.sk" password="pass" port="25"/>
</smtp>
</mailSettings>
C#:
using (SmtpClient client = new SmtpClient())
{
MailMessage message = new MailMessage(from, to, subject, body);
client.Timeout = 10000;
client.Send(message);
return false;
}
The thing is, it doesn't work (I get timeout exception) until I try to send email using outlook. Right after sending email by outlook it successfully sends it also by my web application. Is there some special kind of authentication which outlook is doing which then allows all emails from my IP to be authenticated?? What is the reason it works only after sending it by outlook?
BTW: I'm running the application in VS asp.net development server. When I deploy it to webhosting server, it doesn't work (timeout). My webhosting provider told me there is a classic smtp authentication on that server (not pop3 before smtp).
EDITED:
I figured out, when it worked and I tried it by telnet or traced it by wireshark, the communication started by:
220 mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-PIPELINING
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
...
Compared to when it didn't work (just tried a day before), the whole communication looked like:
220-mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
So there is a difference in supported auth methods and support for pipelining. I guess that System.Net.Mail.SmtpClient then doesn't know which authentication method should it use and so it stucks and therefore I'm getting the timeout exception.
That's interesting that outlook has no problems to connect and send email.
I solved my problem by not using their smtp server, as I'm running out of time. I'm using gmail's smtp server instead. I created new gmail account where I set alias to what I needed, so the email looks like it didn't come from gmail on the first look.