Sending Mail using gmail SMTP from CSharp/.net

前端 未结 3 870
太阳男子
太阳男子 2020-12-20 07:25
using(SmtpClient client = new SmtpClient(\"smtp.gmail.com\", 587)) 
{
    // Configure the client
    client.EnableSsl = true;
    client.UseDefaultCredentials = fal         


        
3条回答
  •  萌比男神i
    2020-12-20 08:19

        message.To.Add(new MailAddress("abc@abc.com));  // replace with valid value 
            message.From = new MailAddress("abc@abc.com", "Contact Form");
            message.Subject = Subject;
            message.Body = string.Format(NewBody);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "abc@gmail.com",  // replace with valid value
                    Password = "qwerty123456"  // replace with valid value
                };
                smtp.Credentials = credential;
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(message);
            }
    

    Just This is working code for me you can use it,Only Problem with this code is sometime mails are coming in spam Folder.

提交回复
热议问题