send email asp.net c#

后端 未结 8 614
别跟我提以往
别跟我提以往 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

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

提交回复
热议问题