Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Net.Mail;
- namespace EmailExample
- {
- public class Email
- {
- /// <summary>
- /// Uses Gmail to send an email
- /// </summary>
- /// <param name="recipient">The email address the message will be sent to</param>
- /// <param name="subject">The subject of the email</param>
- /// <param name="text">The body of the email</param>
- /// <returns>Flag if email was sent successfully or not</returns>
- public static bool SendEmail(string recipient, string subject, string text)
- {
- try
- {
- MailMessage mail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
- // Use your actual email address
- mail.From = new MailAddress("<your_email_address@gmail.com>");
- mail.To.Add(recipient);
- mail.Subject = subject;
- mail.Body = text;
- SmtpServer.Port = 587;
- // Use your actual username and password
- SmtpServer.Credentials =
- new System.Net.NetworkCredential("<username>", "<password>");
- SmtpServer.EnableSsl = true;
- SmtpServer.Send(mail);
- return true;
- }
- catch
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement