Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail using localhost SMTP

Tags:

c#

smtp

iis-6

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.

like image 451
pencilslate Avatar asked Oct 13 '09 02:10

pencilslate


People also ask

Can I send SMTP mail from localhost?

Change the localhost to the smtp server name of your ISP. No need to change the smtp_port . Leave it as 25. Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address.

Can we send mail from localhost in PHP?

The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also send HTML email from localhost in PHP using PHPMailer.

Can we use mail function from localhost?

We can send mail from our localhost using some mail configuration by XAMPP/LAMP/WAMP server, First we need to enable php_openssl php extensions from php. ini file. I am using GMAIL SMTP server to send mail from localhost and sendmail package,It is a mail transport agent which can be found in php.


3 Answers

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; 
like image 122
dave wanta Avatar answered Sep 22 '22 08:09

dave wanta


I think in localhost you can use :

SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(mailMessage);
like image 37
Natim Avatar answered Sep 18 '22 08:09

Natim


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.

like image 23
Joel Coehoorn Avatar answered Sep 18 '22 08:09

Joel Coehoorn