send email asp.net c#

后端 未结 8 542
别跟我提以往
别跟我提以往 2020-12-08 22:59

Is it possible to send email from my computer(localhost) using asp.net project in C#? Finally I am going to upload my project into webserver but I want to test it before upl

相关标签:
8条回答
  • 2020-12-08 23:52

    You can send email from ASP.NET via C# class libraries found in the System.Net.Mail namespace. take a look at the SmtpClient class which is the main class involved when sending emails.

    You can find code examples in Scott Gu's Blog or on the MSDN page of SmtpClient.

    Additionally you'll need an SMTP server running. I can recommend to use SMTP4Dev mail server that targets development and does not require any setup.

    0 讨论(0)
  • 2020-12-08 23:52

    Below is the solution for you if you do not want to use gmail or hotmail:

    SmtpClient smtpClient = new SmtpClient("mail.MyWebsiteDomainName.com", 25);
    
    smtpClient.Credentials = new System.Net.NetworkCredential("info@MyWebsiteDomainName.com", "myIDPassword");
    smtpClient.UseDefaultCredentials = true;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.EnableSsl = true;
    MailMessage mail = new MailMessage();
    
    
    //Setting From , To and CC
    mail.From = new MailAddress("info@MyWebsiteDomainName", "MyWeb Site");
    mail.To.Add(new MailAddress("info@MyWebsiteDomainName"));
    mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
    
    
    smtpClient.Send(mail);
    

    Hope it help :)

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