tags:

views:

2249

answers:

4

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.

Thanks for reading!

+1  A: 

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.

Joel Coehoorn
@Joel:My SMTP server setup:Authentication: Anonymous accessIP address: All UnassignedOutbound security: Anonymous accessCurious, if this is a correct configuration for sending mails without credentials.
pencilslate
That's a question for serverfault.
Joel Coehoorn
+2  A: 

I think in localhost you can use :

SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(mailMessage);
Natim
+4  A: 

Hi,

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;

Cheers! Dave

dave wanta
This is the correct answer for using the local IIS pickup directory. Since it just writes a file, it won't use any credentials at all and IIS will just send it for you.
Jeff Tucker
A: 

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)
mahalie