I am trying to setup SMTP server on IIS for sending mails. The SMTP server is intended to be used by the ASP.NET code in C#.
I was previously using gmail smtp where
I think in localhost you can use :
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(mailMessage);
It depends on how you configure the smtp server. You might not need to use any credentials at all, and just configure the server to only accept local connections.
Tx Natim, what you say worked for me. Have our intranet app using integrated auth with our exchange 2007 server now:
Dim msg As New MailMessage()
Dim smtp As SmtpClient
msg.From = New MailAddress(strFrom)
msg.To.Add(strTo)
msg.Subject = strSubject
msg.Body = strBody
smtp = New SmtpClient("ServerName")
smtp.UseDefaultCredentials = True
smtp.Send(msg)
When you are using the local IIS SMTP service, set the DeliveryMethod to PickupDirectoryFromIis. For example:
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
This totally bypasses the network layer, and writes the messages directly to disk. Its much faster than going through the chatty SMTP protocol.
When you using the above code, it means you can get rid of this part of your code:
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(uname,pwd);
smtpClient.EnableSsl = true;
If you want to test emails in localhost, just download install the papercut tool https://papercut.codeplex.com/
and change hostname to localhost as below. Papercut captures all the emails sending using localhost.
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = "localhost";
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(uname,pwd);
smtpClient.EnableSsl = true;
Have you tried enabling relay?
Find IIS6 manager (I have found that searching for IIS may return 2 results) go to the SMTP server properties then 'Access' then press the relay button.
Then you can either select all or only allow certain ip's like 127.0.0.1