Send mail using localhost SMTP

时光总嘲笑我的痴心妄想 提交于 2019-11-28 21:14:36

I think in localhost you can use :

SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(mailMessage);
dave wanta

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;

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.

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

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

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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!