Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a class I've used in the past:</p> <pre><code>namespace MyApp { public class GMailer { public static string GmailUsername { get; set; } public static string GmailPassword { get; set; } public static string GmailHost { get; set; } public static int GmailPort { get; set; } public static bool GmailSSL { get; set; } public string ToEmail { get; set; } public string Subject { get; set; } public string Body { get; set; } public bool IsHtml { get; set; } static GMailer() { GmailHost = "smtp.gmail.com"; GmailPort = 25; // Gmail can use ports 25, 465 &amp; 587; but must be 25 for medium trust environment. GmailSSL = true; } public void Send() { SmtpClient smtp = new SmtpClient(); smtp.Host = GmailHost; smtp.Port = GmailPort; smtp.EnableSsl = GmailSSL; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(GmailUsername, GmailPassword); using (var message = new MailMessage(GmailUsername, ToEmail)) { message.Subject = Subject; message.Body = Body; message.IsBodyHtml = IsHtml; smtp.Send(message); } } } } </code></pre> <p>The class needs to be configured in your Application_Start event:</p> <pre><code>GMailer.GmailUsername = "you@gmail.com"; GMailer.GmailPassword = "password"; </code></pre> <p>Usage:</p> <pre><code>GMailer mailer = new GMailer(); mailer.ToEmail = "someone@somewhere.com"; mailer.Subject = "Email Subject Line"; mailer.Body = "This is a test message"; mailer.IsHtml = false; mailer.Send(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload