<p>Instead of relying on my host to send an email, I was thinking of sending the email messages using my <strong>Gmail</strong> account. The emails are personalized emails to the bands I play on my show. </p>

<p>Is it possible to do it?</p>

[{'answer_id': 32336, 'author': 'Domenic', 'author_id': 3191, 'author_profile': 'https://Stackoverflow.com/users/3191', 'pm_score': 11, 'selected': True, 'text': '<p>Be sure to use <code>System.Net.Mail</code>, not the deprecated <code>System.Web.Mail</code>. Doing SSL with <code>System.Web.Mail</code> is a gross mess of hacky extensions.</p>\n<pre><code>using System.Net;\nusing System.Net.Mail;\n\nvar fromAddress = new MailAddress(&quot;from@gmail.com&quot;, &quot;From Name&quot;);\nvar toAddress = new MailAddress(&quot;to@example.com&quot;, &quot;To Name&quot;);\nconst string fromPassword = &quot;fromPassword&quot;;\nconst string subject = &quot;Subject&quot;;\nconst string body = &quot;Body&quot;;\n\nvar smtp = new SmtpClient\n{\n    Host = &quot;smtp.gmail.com&quot;,\n    Port = 587,\n    EnableSsl = true,\n    DeliveryMethod = SmtpDeliveryMethod.Network,\n    UseDefaultCredentials = false,\n    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)\n};\nusing (var message = new MailMessage(fromAddress, toAddress)\n{\n    Subject = subject,\n    Body = body\n})\n{\n    smtp.Send(message);\n}\n</code></pre>\n<p>Additionally go to the <a href="https://myaccount.google.com/security" rel="noreferrer"><em>Google Account &gt; Security</em></a> page and look at the <em>Signing in to Google &gt; 2-Step Verification</em> setting.</p>\n<ul>\n<li>If it is enabled, then you have to generate a password allowing .NET to bypass the 2-Step Verification. To do this, click on <a href="https://myaccount.google.com/apppasswords" rel="noreferrer"><em>Signing in to Google &gt; App passwords</em></a>, select app = Mail, and device = Windows Computer, and finally generate the password. Use the generated password in the <code>fromPassword</code> constant instead of your standard Gmail password.</li>\n<li>If it is disabled, then you have to turn on <a href="https://myaccount.google.com/lesssecureapps" rel="noreferrer"><em>Less secure app access</em></a>, which is not recommended! So better enable the 2-Step verification.</li>\n</ul>\n'}, {'answer_id': 489594, 'author': 'Donny V.', 'author_id': 1231, 'author_profile': 'https://Stackoverflow.com/users/1231', 'pm_score': 7, 'selected': False, 'text': '<p>The above answer doesn\'t work. You have to set <code>DeliveryMethod = SmtpDeliveryMethod.Network</code> or it will come back with a "<strong>client was not authenticated</strong>" error. Also it\'s always a good idea to put a timeout.</p>\n\n<p>Revised code:</p>\n\n<pre><code>using System.Net.Mail;\nusing System.Net;\n\nvar fromAddress = new MailAddress("from@gmail.com", "From Name");\nvar toAddress = new MailAddress("to@yahoo.com", "To Name");\nconst string fromPassword = "password";\nconst string subject = "test";\nconst string body = "Hey now!!";\n\nvar smtp = new SmtpClient\n{\n    Host = "smtp.gmail.com",\n    Port = 587,\n    EnableSsl = true,\n    DeliveryMethod = SmtpDeliveryMethod.Network,\n    Credentials = new NetworkCredential(fromAddress.Address, fromPassword),\n    Timeout = 20000\n};\nusing (var message = new MailMessage(fromAddress, toAddress)\n{\n    Subject = subject,\n    Body = body\n})\n{\n    smtp.Send(message);\n}\n</code></pre>\n'}, {'answer_id': 3955349, 'author': 'tehie', 'author_id': 478781, 'author_profile': 'https://Stackoverflow.com/users/478781', 'pm_score': 4, 'selected': False, 'text': '<p>Here is my version: "<a href="http://www.techiespider.com/?p=7" rel="noreferrer">Send Email In C # Using Gmail</a>".</p>\n\n<pre><code>using System;\nusing System.Net;\nusing System.Net.Mail;\n\nnamespace SendMailViaGmail\n{\n   class Program\n   {\n   static void Main(string[] args)\n   {\n\n      //Specify senders gmail address\n      string SendersAddress = "Sendersaddress@gmail.com";\n      //Specify The Address You want to sent Email To(can be any valid email address)\n      string ReceiversAddress = "ReceiversAddress@yahoo.com";\n      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)\n      const string SendersPassword = "Password";\n      //Write the subject of ur mail\n      const string subject = "Testing";\n      //Write the contents of your mail\n      const string body = "Hi This Is my Mail From Gmail";\n\n      try\n      {\n        //we will use Smtp client which allows us to send email using SMTP Protocol\n        //i have specified the properties of SmtpClient smtp within{}\n        //gmails smtp server name is smtp.gmail.com and port number is 587\n        SmtpClient smtp = new SmtpClient\n        {\n           Host = "smtp.gmail.com",\n           Port = 587,\n           EnableSsl = true,\n           DeliveryMethod = SmtpDeliveryMethod.Network,\n           Credentials    = new NetworkCredential(SendersAddress, SendersPassword),\n           Timeout = 3000\n        };\n\n        //MailMessage represents a mail message\n        //it is 4 parameters(From,TO,subject,body)\n\n        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);\n        /*WE use smtp sever we specified above to send the message(MailMessage message)*/\n\n        smtp.Send(message);\n        Console.WriteLine("Message Sent Successfully");\n        Console.ReadKey();\n     }\n\n     catch (Exception ex)\n     {\n        Console.WriteLine(ex.Message);\n        Console.ReadKey();\n     }\n    }\n   }\n }\n</code></pre>\n'}, {'answer_id': 10784857, 'author': 'Ranadheer Reddy', 'author_id': 1215594, 'author_profile': 'https://Stackoverflow.com/users/1215594', 'pm_score': 6, 'selected': False, 'text': '<p>This is to send email with attachement.. Simple and short..</p>\n\n<p>source: <a href="http://coding-issues.blogspot.in/2012/11/sending-email-with-attachments-from-c.html">http://coding-issues.blogspot.in/2012/11/sending-email-with-attachments-from-c.html</a></p>\n\n<pre><code>using System.Net;\nusing System.Net.Mail;\n\npublic void email_send()\n{\n    MailMessage mail = new MailMessage();\n    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");\n    mail.From = new MailAddress("your mail@gmail.com");\n    mail.To.Add("to_mail@gmail.com");\n    mail.Subject = "Test Mail - 1";\n    mail.Body = "mail with attachment";\n\n    System.Net.Mail.Attachment attachment;\n    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");\n    mail.Attachments.Add(attachment);\n\n    SmtpServer.Port = 587;\n    SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");\n    SmtpServer.EnableSsl = true;\n\n    SmtpServer.Send(mail);\n\n}\n</code></pre>\n'}, {'answer_id': 12073195, 'author': 'Yasser Shaikh', 'author_id': 1182982, 'author_profile': 'https://Stackoverflow.com/users/1182982', 'pm_score': 4, 'selected': False, 'text': '<p><strong>Source</strong> : <a href="http://yassershaikh.com/how-to-send-email-in-asp-net-c-mvc-3-with-sample-working-code/" rel="noreferrer">Send email in ASP.NET C#</a></p>\n\n<p>Below is a sample working code for sending in a mail using C#, in the below example I am using google’s smtp server. </p>\n\n<p>The code is pretty self explanatory, replace email and password with your email and password values.</p>\n\n<pre><code>public void SendEmail(string address, string subject, string message)\n{\n    string email = "yrshaikh.mail@gmail.com";\n    string password = "put-your-GMAIL-password-here";\n\n    var loginInfo = new NetworkCredential(email, password);\n    var msg = new MailMessage();\n    var smtpClient = new SmtpClient("smtp.gmail.com", 587);\n\n    msg.From = new MailAddress(email);\n    msg.To.Add(new MailAddress(address));\n    msg.Subject = subject;\n    msg.Body = message;\n    msg.IsBodyHtml = true;\n\n    smtpClient.EnableSsl = true;\n    smtpClient.UseDefaultCredentials = false;\n    smtpClient.Credentials = loginInfo;\n    smtpClient.Send(msg);\n}\n</code></pre>\n'}, {'answer_id': 17516257, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 3, 'selected': False, 'text': '<p>Changing sender on Gmail / Outlook.com email:</p>\n\n<p>To prevent spoofing - Gmail/Outlook.com won\'t let you send from an arbitrary user account name.</p>\n\n<p>If you have a limited number of senders you can follow these instructions and then set the <code>From</code> field to this address: <a href="http://support.google.com/a/bin/answer.py?hl=en&amp;answer=22370" rel="noreferrer">Sending mail from a different address</a></p>\n\n<p>If you are wanting to send from an arbitrary email address (such as a feedback form on website where the user enters their email and you don\'t want them emailing you directly) about the best you can do is this :</p>\n\n<pre><code>        msg.ReplyToList.Add(new System.Net.Mail.MailAddress(email, friendlyName));\n</code></pre>\n\n<p>This would let you just hit \'reply\' in your email account to reply to the fan of your band on a feedback page, but they wouldn\'t get your actual email which would likely lead to a tonne of spam.</p>\n\n<p>If you\'re in a controlled environment this works great, but please note that I\'ve seen some email clients send to the from address even when reply-to is specified (I don\'t know which).</p>\n'}, {'answer_id': 17806790, 'author': 'RAJESH KUMAR', 'author_id': 2598139, 'author_profile': 'https://Stackoverflow.com/users/2598139', 'pm_score': 3, 'selected': False, 'text': '<p>If you want to send background email, then please do the below</p>\n\n<pre><code> public void SendEmail(string address, string subject, string message)\n {\n Thread threadSendMails;\n threadSendMails = new Thread(delegate()\n    {\n\n      //Place your Code here \n\n     });\n  threadSendMails.IsBackground = true;\n  threadSendMails.Start();\n}\n</code></pre>\n\n<p>and add namespace</p>\n\n<pre><code>using System.Threading;\n</code></pre>\n'}, {'answer_id': 19240345, 'author': 'iTURTEV', 'author_id': 2853517, 'author_profile': 'https://Stackoverflow.com/users/2853517', 'pm_score': 2, 'selected': False, 'text': '<p>Here is one method to send mail and getting credentials from web.config:</p>\n\n<pre><code>public static string SendEmail(string To, string Subject, string Msg, bool bodyHtml = false, bool test = false, Stream AttachmentStream = null, string AttachmentType = null, string AttachmentFileName = null)\n{\n    try\n    {\n        System.Net.Mail.MailMessage newMsg = new System.Net.Mail.MailMessage(System.Configuration.ConfigurationManager.AppSettings["mailCfg"], To, Subject, Msg);\n        newMsg.BodyEncoding = System.Text.Encoding.UTF8;\n        newMsg.HeadersEncoding = System.Text.Encoding.UTF8;\n        newMsg.SubjectEncoding = System.Text.Encoding.UTF8;\n\n        System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();\n        if (AttachmentStream != null &amp;&amp; AttachmentType != null &amp;&amp; AttachmentFileName != null)\n        {\n            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentStream, AttachmentFileName);\n            System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;\n            disposition.FileName = AttachmentFileName;\n            disposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachment;\n\n            newMsg.Attachments.Add(attachment);\n        }\n        if (test)\n        {\n            smtpClient.PickupDirectoryLocation = "C:\\\\TestEmail";\n            smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;\n        }\n        else\n        {\n            //smtpClient.EnableSsl = true;\n        }\n\n        newMsg.IsBodyHtml = bodyHtml;\n        smtpClient.Send(newMsg);\n        return SENT_OK;\n    }\n    catch (Exception ex)\n    {\n\n        return "Error: " + ex.Message\n             + "&lt;br/&gt;&lt;br/&gt;Inner Exception: "\n             + ex.InnerException;\n    }\n\n}\n</code></pre>\n\n<p>And the corresponding section in web.config:</p>\n\n<pre><code>&lt;appSettings&gt;\n    &lt;add key="mailCfg" value="yourmail@example.com"/&gt;\n&lt;/appSettings&gt;\n&lt;system.net&gt;\n  &lt;mailSettings&gt;\n    &lt;smtp deliveryMethod="Network" from="yourmail@example.com"&gt;\n      &lt;network defaultCredentials="false" host="mail.exapmple.com" userName="yourmail@example.com" password="your_password" port="25"/&gt;\n    &lt;/smtp&gt;\n  &lt;/mailSettings&gt;\n&lt;/system.net&gt;\n</code></pre>\n'}, {'answer_id': 19272274, 'author': 'GOPI', 'author_id': 2522714, 'author_profile': 'https://Stackoverflow.com/users/2522714', 'pm_score': 4, 'selected': False, 'text': '<p>Include this,</p>\n<pre><code>using System.Net.Mail;\n</code></pre>\n<p>And then,</p>\n<pre><code>MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); \nSmtpClient client = new SmtpClient(&quot;smtp.gmail.com&quot;);\n\nclient.Port = 587;\nclient.Credentials = new System.Net.NetworkCredential(&quot;mail-id@gmail.com&quot;,&quot;password&quot;);\nclient.EnableSsl = true;\n\nclient.Send(sendmsg);\n</code></pre>\n'}, {'answer_id': 19378314, 'author': 'Premdeep Mohanty', 'author_id': 2749766, 'author_profile': 'https://Stackoverflow.com/users/2749766', 'pm_score': 4, 'selected': False, 'text': '<p>I hope this code will work fine. You can have a try.</p>\n\n<pre><code>// Include this.                \nusing System.Net.Mail;\n\nstring fromAddress = "xyz@gmail.com";\nstring mailPassword = "*****";       // Mail id password from where mail will be sent.\nstring messageBody = "Write the body of the message here.";\n\n\n// Create smtp connection.\nSmtpClient client = new SmtpClient();\nclient.Port = 587;//outgoing port for the mail.\nclient.Host = "smtp.gmail.com";\nclient.EnableSsl = true;\nclient.Timeout = 10000;\nclient.DeliveryMethod = SmtpDeliveryMethod.Network;\nclient.UseDefaultCredentials = false;\nclient.Credentials = new System.Net.NetworkCredential(fromAddress, mailPassword);\n\n\n// Fill the mail form.\nvar send_mail = new MailMessage();\n\nsend_mail.IsBodyHtml = true;\n//address from where mail will be sent.\nsend_mail.From = new MailAddress("from@gmail.com");\n//address to which mail will be sent.           \nsend_mail.To.Add(new MailAddress("to@example.com");\n//subject of the mail.\nsend_mail.Subject = "put any subject here";\n\nsend_mail.Body = messageBody;\nclient.Send(send_mail);\n</code></pre>\n'}, {'answer_id': 20907006, 'author': 'Mark Homans', 'author_id': 2009368, 'author_profile': 'https://Stackoverflow.com/users/2009368', 'pm_score': 5, 'selected': False, 'text': '<p>For me to get it to work, i had to enable my gmail account making it possible for other apps to gain access. This is done with the "enable less secure apps" and <strong>also</strong> using this link:\n<a href="https://accounts.google.com/b/0/DisplayUnlockCaptcha" rel="noreferrer">https://accounts.google.com/b/0/DisplayUnlockCaptcha</a></p>\n'}, {'answer_id': 25216277, 'author': 'mjb', 'author_id': 520848, 'author_profile': 'https://Stackoverflow.com/users/520848', 'pm_score': 5, 'selected': False, 'text': '<p>Google may block sign in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safer.</p>\n\n<p>Some examples of apps that do not support the latest security standards include:</p>\n\n<ul>\n<li>The Mail app on your iPhone or iPad with iOS 6 or below<br /></li>\n<li>The Mail app on your Windows phone preceding the 8.1 release<br /></li>\n<li>Some Desktop mail clients like Microsoft Outlook and Mozilla Thunderbird</li>\n</ul>\n\n<p>Therefore, you have to enable <b>Less Secure Sign-In</b> in your google account.</p>\n\n<p>After sign into google account, go to:</p>\n\n<p><a href="https://myaccount.google.com/lesssecureapps" rel="noreferrer">https://myaccount.google.com/lesssecureapps</a> <br />\nor <br />\n<a href="https://www.google.com/settings/security/lesssecureapps" rel="noreferrer">https://www.google.com/settings/security/lesssecureapps</a> <br /></p>\n\n<p>In C#, you can use the following code:</p>\n\n<pre><code>using (MailMessage mail = new MailMessage())\n{\n    mail.From = new MailAddress("email@gmail.com");\n    mail.To.Add("somebody@domain.com");\n    mail.Subject = "Hello World";\n    mail.Body = "&lt;h1&gt;Hello&lt;/h1&gt;";\n    mail.IsBodyHtml = true;\n    mail.Attachments.Add(new Attachment("C:\\\\file.zip"));\n\n    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))\n    {\n        smtp.Credentials = new NetworkCredential("email@gmail.com", "password");\n        smtp.EnableSsl = true;\n        smtp.Send(mail);\n    }\n}\n</code></pre>\n'}, {'answer_id': 31043524, 'author': 'DarkPh03n1X', 'author_id': 3431863, 'author_profile': 'https://Stackoverflow.com/users/3431863', 'pm_score': 2, 'selected': False, 'text': '<p>I had the same issue, but it was resolved by going to gmail\'s security settings and <strong>Allowing Less Secure apps</strong>.\nThe Code from Domenic &amp; Donny works, but only if you enabled that setting</p>\n\n<p>If you are signed in (to Google) you can follow <a href="https://www.google.com/settings/security/lesssecureapps" rel="nofollow">this</a> link and toggle <strong>"Turn on"</strong> for <strong>"Access for less secure apps"</strong></p>\n'}, {'answer_id': 31310222, 'author': 'alireza amini', 'author_id': 3970128, 'author_profile': 'https://Stackoverflow.com/users/3970128', 'pm_score': 3, 'selected': False, 'text': '<p>use this way </p>\n\n<pre><code>MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); \nSmtpClient client = new SmtpClient("smtp.gmail.com");\n\nclient.Port = Convert.ToInt32("587");\nclient.EnableSsl = true;\nclient.Credentials = new System.Net.NetworkCredential("mail-id@gmail.com","MyPassWord");\nclient.Send(sendmsg);\n</code></pre>\n\n<p>Don\'t forget this :</p>\n\n<pre><code>using System.Net;\nusing System.Net.Mail;\n</code></pre>\n'}, {'answer_id': 32457468, 'author': 'BCS Software', 'author_id': 4222871, 'author_profile': 'https://Stackoverflow.com/users/4222871', 'pm_score': 7, 'selected': False, 'text': '<p><strong>Edit 2022</strong>\nStarting May 30, 2022, <a href="https://support.google.com/accounts/answer/6010255?hl=en" rel="noreferrer">\u200b\u200bGoogle will no longer support</a> the use of third-party apps or devices which ask you to sign in to your Google Account using only  your username and password.\n<strong>But you still can send E-Mail via your gmail account.</strong></p>\n<ol>\n<li>Go to <a href="https://myaccount.google.com/security" rel="noreferrer">https://myaccount.google.com/security</a> and turn on <strong>two step verification</strong>. Confirm your account by phone if needed.</li>\n<li>Click &quot;App Passwords&quot;, just below the &quot;2 step verification&quot; tick.</li>\n<li>Request a new password for the mail app.\n<a href="https://i.stack.imgur.com/LhP5V.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LhP5V.png" alt="enter image description here" /></a></li>\n</ol>\n<p>Now just use this password instead of the original one for you account!</p>\n<pre><code>public static void SendMail2Step(string SMTPServer, int SMTP_Port, string From, string Password, string To, string Subject, string Body, string[] FileNames) {            \n            var smtpClient = new SmtpClient(SMTPServer, SMTP_Port) {\n                DeliveryMethod = SmtpDeliveryMethod.Network,\n                UseDefaultCredentials = false,\n                EnableSsl = true\n            };                \n            smtpClient.Credentials = new NetworkCredential(From, Password); //Use the new password, generated from google!\n            var message = new System.Net.Mail.MailMessage(new System.Net.Mail.MailAddress(From, &quot;SendMail2Step&quot;), new System.Net.Mail.MailAddress(To, To));\n            smtpClient.Send(message);\n    }\n</code></pre>\n<p>Use like this:</p>\n<pre><code>SendMail2Step(&quot;smtp.gmail.com&quot;, 587, &quot;youraccount@gmail.com&quot;,\n          &quot;yjkjcipfdfkytgqv&quot;,//This will be generated by google, copy it here.\n          &quot;recipient@barcodes.bg&quot;, &quot;test message subject&quot;, &quot;Test message body ...&quot;, null);\n</code></pre>\n<p>For the other answers to work &quot;from a server&quot; first <strong>Turn On Access for less secure apps</strong> in the gmail account. <strong>This will be deprecated 30 May 2022</strong></p>\n<p>Looks like recently google changed it\'s security policy. The top rated answer no longer works, until you change your account settings as described here: <a href="https://support.google.com/accounts/answer/6010255?hl=en-GB" rel="noreferrer">https://support.google.com/accounts/answer/6010255?hl=en-GB</a>\n<strong>As of March 2016, google changed the setting location again!</strong>\n<a href="https://i.stack.imgur.com/XqODf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XqODf.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 33054757, 'author': 'Moin Shirazi', 'author_id': 4033273, 'author_profile': 'https://Stackoverflow.com/users/4033273', 'pm_score': 3, 'selected': False, 'text': '<pre><code>using System;\nusing System.Net;\nusing System.Net.Mail;\n\nnamespace SendMailViaGmail\n{\n   class Program\n   {\n   static void Main(string[] args)\n   {\n\n      //Specify senders gmail address\n      string SendersAddress = "Sendersaddress@gmail.com";\n      //Specify The Address You want to sent Email To(can be any valid email address)\n      string ReceiversAddress = "ReceiversAddress@yahoo.com";\n      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)\n      const string SendersPassword = "Password";\n      //Write the subject of ur mail\n      const string subject = "Testing";\n      //Write the contents of your mail\n      const string body = "Hi This Is my Mail From Gmail";\n\n      try\n      {\n        //we will use Smtp client which allows us to send email using SMTP Protocol\n        //i have specified the properties of SmtpClient smtp within{}\n        //gmails smtp server name is smtp.gmail.com and port number is 587\n        SmtpClient smtp = new SmtpClient\n        {\n           Host = "smtp.gmail.com",\n           Port = 587,\n           EnableSsl = true,\n           DeliveryMethod = SmtpDeliveryMethod.Network,\n           Credentials = new NetworkCredential(SendersAddress, SendersPassword),\n           Timeout = 3000\n        };\n\n        //MailMessage represents a mail message\n        //it is 4 parameters(From,TO,subject,body)\n\n        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);\n        /*WE use smtp sever we specified above to send the message(MailMessage message)*/\n\n        smtp.Send(message);\n        Console.WriteLine("Message Sent Successfully");\n        Console.ReadKey();\n     }\n     catch (Exception ex)\n     {\n        Console.WriteLine(ex.Message);\n        Console.ReadKey();\n     }\n}\n}\n}\n</code></pre>\n'}, {'answer_id': 35669909, 'author': 'reza.cse08', 'author_id': 2597706, 'author_profile': 'https://Stackoverflow.com/users/2597706', 'pm_score': 2, 'selected': False, 'text': '<p>Try this one </p>\n\n<pre><code>public static bool Send(string receiverEmail, string ReceiverName, string subject, string body)\n{\n        MailMessage mailMessage = new MailMessage();\n        MailAddress mailAddress = new MailAddress("abc@gmail.com", "Sender Name"); // abc@gmail.com = input Sender Email Address \n        mailMessage.From = mailAddress;\n        mailAddress = new MailAddress(receiverEmail, ReceiverName);\n        mailMessage.To.Add(mailAddress);\n        mailMessage.Subject = subject;\n        mailMessage.Body = body;\n        mailMessage.IsBodyHtml = true;\n\n        SmtpClient mailSender = new SmtpClient("smtp.gmail.com", 587)\n        {\n            EnableSsl = true,\n            UseDefaultCredentials = false,\n            DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,\n            Credentials = new NetworkCredential("abc@gmail.com", "pass")   // abc@gmail.com = input sender email address  \n                                                                           //pass = sender email password\n        };\n\n        try\n        {\n            mailSender.Send(mailMessage);\n            return true;\n        }\n        catch (SmtpFailedRecipientException ex)\n        { \n          // Write the exception to a Log file.\n        }\n        catch (SmtpException ex)\n        { \n           // Write the exception to a Log file.\n        }\n        finally\n        {\n            mailSender = null;\n            mailMessage.Dispose();\n        }\n        return false;\n}\n</code></pre>\n'}, {'answer_id': 41952779, 'author': 'Trimantra Software Solution', 'author_id': 777171, 'author_profile': 'https://Stackoverflow.com/users/777171', 'pm_score': 3, 'selected': False, 'text': '<p>Try This,</p>\n\n<pre><code>    private void button1_Click(object sender, EventArgs e)\n    {\n        try\n        {\n            MailMessage mail = new MailMessage();\n            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");\n\n            mail.From = new MailAddress("your_email_address@gmail.com");\n            mail.To.Add("to_address");\n            mail.Subject = "Test Mail";\n            mail.Body = "This is for testing SMTP mail from GMAIL";\n\n            SmtpServer.Port = 587;\n            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");\n            SmtpServer.EnableSsl = true;\n\n            SmtpServer.Send(mail);\n            MessageBox.Show("mail Send");\n        }\n        catch (Exception ex)\n        {\n            MessageBox.Show(ex.ToString());\n        }\n    }\n</code></pre>\n'}, {'answer_id': 49429541, 'author': 'rogerdpack', 'author_id': 32453, 'author_profile': 'https://Stackoverflow.com/users/32453', 'pm_score': 1, 'selected': False, 'text': '<p>Copying from <a href="https://stackoverflow.com/a/19723382/32453">another answer</a>, the above methods work but gmail always replaces the "from" and "reply to" email with the actual sending gmail account.  apparently there is a work around however:</p>\n\n<p><a href="http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html" rel="nofollow noreferrer">http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html</a></p>\n\n<p>"3. In the Accounts Tab, Click on the link "Add another email address you own" then verify it"</p>\n\n<p>Or possibly <a href="https://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server" rel="nofollow noreferrer">this</a></p>\n\n<p>Update 3: Reader Derek Bennett says, "The solution is to go into your gmail Settings:Accounts and "Make default" an account other than your gmail account. This will cause gmail to re-write the From field with whatever the default account\'s email address is."</p>\n'}, {'answer_id': 56423660, 'author': 'Naveen', 'author_id': 5718260, 'author_profile': 'https://Stackoverflow.com/users/5718260', 'pm_score': 2, 'selected': False, 'text': '<p>You can try <code>Mailkit</code>. It gives you better and advance functionality for send mail. You can find more from <a href="https://github.com/jstedfast/MailKit" rel="nofollow noreferrer">this</a> Here is an example </p>\n\n<pre><code>    MimeMessage message = new MimeMessage();\n    message.From.Add(new MailboxAddress("FromName", "YOU_FROM_ADDRESS@gmail.com"));\n    message.To.Add(new MailboxAddress("ToName", "YOU_TO_ADDRESS@gmail.com"));\n    message.Subject = "MyEmailSubject";\n\n    message.Body = new TextPart("plain")\n    {\n        Text = @"MyEmailBodyOnlyTextPart"\n    };\n\n    using (var client = new SmtpClient())\n    {\n        client.Connect("SERVER", 25); // 25 is port you can change accordingly\n\n        // Note: since we don\'t have an OAuth2 token, disable\n        // the XOAUTH2 authentication mechanism.\n        client.AuthenticationMechanisms.Remove("XOAUTH2");\n\n        // Note: only needed if the SMTP server requires authentication\n        client.Authenticate("YOUR_USER_NAME", "YOUR_PASSWORD");\n\n        client.Send(message);\n        client.Disconnect(true);\n    }\n</code></pre>\n'}, {'answer_id': 57067328, 'author': 'Sayed Uz Zaman', 'author_id': 10119759, 'author_profile': 'https://Stackoverflow.com/users/10119759', 'pm_score': 4, 'selected': False, 'text': '<p>To avoid security issues in Gmail, you should generate an app password first from your Gmail settings and you can use this password instead of a real password to send an email even if you use two steps verification.</p>\n'}, {'answer_id': 63782647, 'author': 'Hasala Senevirathne', 'author_id': 7292121, 'author_profile': 'https://Stackoverflow.com/users/7292121', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://i.stack.imgur.com/xrl3W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xrl3W.png" alt="How to Set App-specific password for gmail" /></a></p>\n<p>If your Google password doesn\'t work, you may need to create an app-specific password for Gmail on Google.\n<a href="https://support.google.com/accounts/answer/185833?hl=en" rel="nofollow noreferrer">https://support.google.com/accounts/answer/185833?hl=en</a></p>\n'}, {'answer_id': 73352730, 'author': 'Sunny Okoro Awa', 'author_id': 2623765, 'author_profile': 'https://Stackoverflow.com/users/2623765', 'pm_score': 1, 'selected': False, 'text': '<p>This is no longer supported incase you are trying to do this now.</p>\n<p><a href="https://support.google.com/accounts/answer/6010255?hl=en&amp;visit_id=637960864118404117-800836189&amp;p=less-secure-apps&amp;rd=1#zippy=" rel="nofollow noreferrer">https://support.google.com/accounts/answer/6010255?hl=en&amp;visit_id=637960864118404117-800836189&amp;p=less-secure-apps&amp;rd=1#zippy=</a></p>\n<p><a href="https://i.stack.imgur.com/y5zYQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y5zYQ.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 74054933, 'author': 'Bhadresh Patel', 'author_id': 3134543, 'author_profile': 'https://Stackoverflow.com/users/3134543', 'pm_score': 2, 'selected': False, 'text': '<p><strong>From 1 Jun 2022, \u200b\u200bGoogle has added some security features</strong></p>\n<p>Google is no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password or send mail directly using username and password of google account. But you still can send E-Mail via your gmail account using generating app password.</p>\n<blockquote>\n<p>Below are the steps for generate new password.</p>\n</blockquote>\n<ol>\n<li>Go to <a href="https://myaccount.google.com/security" rel="nofollow noreferrer">https://myaccount.google.com/security</a></li>\n<li>Turn on two step verification.</li>\n<li>Confirm your account by phone if needed.</li>\n<li>Click &quot;App Passwords&quot;, just below the &quot;2 step verification&quot; tick. Request a new password for the mail app.</li>\n</ol>\n<p>Now we have to use this password for sending mail instead of the original password of your account.</p>\n<blockquote>\n<p>Below is the example code for sending mail</p>\n</blockquote>\n<pre><code>public static void SendMailFromApp(string SMTPServer, int SMTP_Port, string From, string Password, string To, string Subject, string Body) {            \n            var smtpClient = new SmtpClient(SMTPServer, SMTP_Port) {\n                DeliveryMethod = SmtpDeliveryMethod.Network,\n                UseDefaultCredentials = false,\n                EnableSsl = true\n            };                \n            smtpClient.Credentials = new NetworkCredential(From, Password); //Use the new password, generated from google!\n            var message = new System.Net.Mail.MailMessage(new System.Net.Mail.MailAddress(From, &quot;SendMail2Step&quot;), new System.Net.Mail.MailAddress(To, To));\n            smtpClient.Send(message);\n    }\n</code></pre>\n<p>You can to call method like below</p>\n<pre><code>SendMailFromApp(&quot;smtp.gmail.com&quot;, 25, &quot;mygmailaccount@gmail.com&quot;,\n          &quot;tyugyyj1556jhghg&quot;,//This will be generated by google, copy it here.\n          &quot;mailme@gmail.com&quot;, &quot;New Mail Subject&quot;, &quot;Body of mail from My App&quot;);\n</code></pre>\n'}, {'answer_id': 74404794, 'author': 'DaImTo', 'author_id': 1841839, 'author_profile': 'https://Stackoverflow.com/users/1841839', 'pm_score': 1, 'selected': False, 'text': '<p><a href="https://i.stack.imgur.com/Y5W1l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y5W1l.png" alt="enter image description here" /></a></p>\n<p>Google has removed the less secure apps setting from our Google accounts, this means that we can no longer send emails from the SMTP server using our actual google passwords.  We need to either use Xoauth2 and authorize the user or create a an apps password on an account that has 2fa enabled.</p>\n<p>Once created an apps password can be used in place of your standard gmail password.</p>\n<pre><code>class Program\n{\n    private const string To = &quot;test@test.com&quot;;\n    private const string From = &quot;test@test.com&quot;;\n    \n    private const string GoogleAppPassword = &quot;XXXXXXXX&quot;;\n    \n    private const string Subject = &quot;Test email&quot;;\n    private const string Body = &quot;&lt;h1&gt;Hello&lt;/h1&gt;&quot;;\n    \n    \n    static void Main(string[] args)\n    {\n        Console.WriteLine(&quot;Hello World!&quot;);\n        \n        var smtpClient = new SmtpClient(&quot;smtp.gmail.com&quot;)\n        {\n            Port = 587,\n            Credentials = new NetworkCredential(From , GoogleAppPassword),\n            EnableSsl = true,\n        };\n        var mailMessage = new MailMessage\n        {\n            From = new MailAddress(From),\n            Subject = Subject,\n            Body = Body,\n            IsBodyHtml = true,\n        };\n        mailMessage.To.Add(To);\n\n        smtpClient.Send(mailMessage);\n    }\n}\n</code></pre>\n<p><a href="https://www.youtube.com/watch?v=Y_u5KIeXiVI" rel="nofollow noreferrer">Quick fix for SMTP username and password not accepted error</a></p>\n'}]
['https://Stackoverflow.com/questions/32260', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2535/']