Send mail using localhost SMTP

后端 未结 6 1966
失恋的感觉
失恋的感觉 2020-12-14 07:41

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

相关标签:
6条回答
  • 2020-12-14 08:07

    I think in localhost you can use :

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Send(mailMessage);
    
    0 讨论(0)
  • 2020-12-14 08:10

    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.

    0 讨论(0)
  • 2020-12-14 08:12

    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) 
    
    0 讨论(0)
  • 2020-12-14 08:14

    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;
    
    0 讨论(0)
  • 2020-12-14 08:18

    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;
    
    0 讨论(0)
  • 2020-12-14 08:24

    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

    SMTP Relay

    0 讨论(0)
提交回复
热议问题