Send Mail using Localhost SMTP #
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 wherein i provided the smtp.gmail.com as host with secure port and my gmail uid/pwd. That worked fine. Here is the code used to do that.
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = “smtp.gmail.com”;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(uname,pwd);
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);
Now i am planning to use the localhost SMTP server on IIS, what values should i be giving for the parameters UseDefaultCredentials and Credentials. I will be assigning false to EnableSsl as it’s over port 25.
Also, what could be the most simple SMTP virtual server configuration.
Here is Some Solutions :
Solution 1: #
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(mailMessage);
Solution 2: #
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = “smtp.gmail.com”;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(uname,pwd);
smtpClient.EnableSsl = true;
Solution 3: #
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = “localhost”;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(uname,pwd);
smtpClient.EnableSsl = true;
Solution 4: #
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)