Sending an email to the local domain

后端 未结 3 1125
孤街浪徒
孤街浪徒 2021-01-13 17:42

I\'ve got a simple method to send emails from the website:

... // local vars
using (var mail = new MailMessage(from, sendTo))
{
    using (var smtp = new Smt         


        
3条回答
  •  渐次进展
    2021-01-13 18:00

    I made a tool for sending email`s with this configurations:

    MailMessage mail = new MailMessage("senderaddress", "recipientaddress");
    SmtpClient client = new SmtpClient()
    {
        Host = "smtpserver",
        Port = 587,//standard port for the most of the server`s
        DeliveryMethod = SmtpDeliveryMethod.Network,
        EnableSsl = true,
        UseDefaultCredentials = false//I got the address and the password so I don`t need the default-credentials
    };
    NetworkCredential na = new NetworkCredential("yoursender", "senderpassword");//I let the user input his email-address and password to get auntenthificated 
    client.Credentials = na;
    mail.Subject = "subject";
    
    mail.Body = "body";
    mail.IsBodyHtml = true;//I use to send html formated text
    
    try
    {
        client.Send(mail);
    }
    catch (Exception)//for debugging purposes I used the default exception
    {
        MessageBox.Show("Sending failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    

    It worked fine for me, when I wanted to send from one domain to the same host, so I hope it works also fine for you!

提交回复
热议问题