Wednesday, January 10, 2018

Sending email in .NET through Gmail

C# Code Is: 

 var fromAddress = new MailAddress("unbroken4420@gmail.com", "Zihadul");
              var toAddress = new MailAddress("rajon5000@gmail.com", "Rajon");
              const string fromPassword = "*******";
              const string subject = "Subject";
              const string body = "Body";

              var smtp = new SmtpClient
              {
                  Host = "smtp.gmail.com",
                  Port = 587,
                  EnableSsl = true,
                  DeliveryMethod = SmtpDeliveryMethod.Network,
                  UseDefaultCredentials = false,
                  Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
              };
              using (var message = new MailMessage(fromAddress, toAddress)
              {
                  Subject = subject,
                  Body = body
              })
              {
                  smtp.Send(message);
              }

No comments:

Post a Comment