public string sendit(string ReciverMail)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("YourMail@gmail.com");
msg.To.Add(ReciverMail);
msg.Subject = "Hello world! " + DateTime.Now.ToString();
msg.Body = "hi to you ... :)";
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("YourMail@gmail.com", "YourPassword");
client.Timeout = 20000;
try
{
client.Send(msg);
return "Mail has been successfully sent!";
}
catch (Exception ex)
{
return "Fail Has error" + ex.Message;
}
finally
{
msg.Dispose();
}
}
source : https://stackoverflow.com/questions/29465096/how-to-send-an-e-mail-with-c-sharp-through-gmail
'C#(CSharp) > Etc' 카테고리의 다른 글
TraceListener (0) | 2017.12.07 |
---|---|
Simple and Powerful Debug function (0) | 2017.10.18 |
BlockingQueue (BlockingCollection) (0) | 2017.08.07 |
윈도우 8 메트로 스타일 App Deploy 관련해서... (0) | 2015.04.08 |
Microsoft Visual Studio Installer in VS2013 (0) | 2015.03.21 |