{"id":536,"date":"2013-09-03T11:38:28","date_gmt":"2013-09-03T11:38:28","guid":{"rendered":"http:\/\/ntspl.co.in\/blog\/?p=536"},"modified":"2021-12-20T11:04:01","modified_gmt":"2021-12-20T11:04:01","slug":"send-mail-in-gmail-account-using-asp-net","status":"publish","type":"post","link":"https:\/\/www.ntspl.co.in\/blog\/send-mail-in-gmail-account-using-asp-net\/","title":{"rendered":"Send Mail in Gmail Account Using ASP.Net"},"content":{"rendered":"<p>Generally if you write the code for sendmail in asp.net using gmail account. It may not work on online. That time you have to Unlocking Google&#8217;s Gmail account.<\/p>\n<p><strong>Mail Coding:<\/strong><\/p>\n<pre class=\"code-structure\"><code>\r\n<span class=\"comment\">\/\/-------------------------Start Code----------------------------------------<\/span>\r\npublic bool sendMail(string eidTo, string msgsub, string msgbody) {\r\n\r\n\tMailMessage greetings = new MailMessage();\r\n\tSmtpClient smtp = new SmtpClient();\r\n\ttry {\r\n\t\r\n\t\tgreetings.From = new MailAddress(\"xyz@gmail.com\", \"demo\");\r\n\t\tgreetings.To.Add(eidTo);\r\n\t\tgreetings.IsBodyHtml = true;\r\n\t\tgreetings.Priority = MailPriority.High;\r\n\t\tgreetings.Body = msgbody;\r\n\t\tgreetings.Subject = msgsub;\r\n\t\t\r\n\t\tsmtp.Host = \"smtp.gmail.com\";\r\n\t\tsmtp.Port = 587;\r\n\t\tsmtp.EnableSsl = true;\r\n\t\tsmtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;\r\n\t\tsmtp.UseDefaultCredentials = false;\r\n\t\tsmtp.Credentials = new System.Net.NetworkCredential(\"xyz@gmail.com\", \"xyzpassword\");\r\n\t\tsmtp.Send(greetings);\r\n\t\treturn true;\r\n\t\t\r\n\t}\r\n\tcatch (Exception) { throw; }\r\n\r\n}\r\n<span class=\"comment\">\/\/-------------------------End code------------------------------<\/span>\r\n<\/code><\/pre>\n<p>Google may prevent an application from accessing your account<br \/>\nHere you can enable applications to access google account with your credentials:<\/p>\n<p>https:\/\/accounts.google.com\/DisplayUnlockCaptcha<br \/>\n(Login gmail account &amp; click the above link)<br \/>\nSet UseDefaultCredentials to false, since you define credentials for the connection.<\/p>\n<p>Set this property to true when this SmtpClient object should, if requested by the server, authenticate using the default credentials of the currently logged on user.<\/p>\n<p>If the UseDefaultCredentials property is set to false, then the value set in the Credentials property will be used for the credentials when connecting to the server.<br \/>\nHappy coding&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Generally if you write the code for sendmail in asp.net using gmail account. It may not work on online. That time you have to Unlocking Google&#8217;s Gmail account. Mail Coding: \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-Start Code&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- public bool sendMail(string eidTo, string msgsub, string msgbody) { MailMessage greetings = new MailMessage(); SmtpClient smtp = new SmtpClient(); try { greetings.From = [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":1487,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,32],"tags":[327],"class_list":["post-536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-dot-net","category-tutorials","tag-smtp-mail"],"acf":{"custom_meta_title":"How to Send Mail in Gmail Account Using ASP.Net? | NTSPL","meta_description":"Do you know how to send mail in gmail accounts using asp.net? Here is the technique to send mail in gmail accounts using asp.net. Read the complete blog.","meta_keyword":"mails using asp.net, send mails using asp.net","other_meta_tag":"<meta property=og:locale content=\"en-IN\" \/>\r\n<meta property=og:type content=\"website\" \/>\r\n<meta property=og:title content=\"How to Send Mail in Gmail Account Using ASP.Net? | NTSPL\"\/>\r\n<meta property=og:description content=\"Do you know how to send mail in gmail accounts using asp.net? Here is the technique to send mail in gmail accounts using asp.net. Read the complete blog.\"\/>\r\n<meta property=og:url content=\"https:\/\/www.ntspl.co.in\/blog\/send-mail-in-gmail-account-using-asp-net\"\/>\r\n<meta property=og:site_name content=NTSPL \/>\r\n<meta name=\"twitter:site\" content=\"@NTSPL\">\r\n<meta name=twitter:card content=\"summary\" \/>\r\n<meta name=twitter:description content=\"Do you know how to send mail in gmail accounts using asp.net? Here is the technique to send mail in gmail accounts using asp.net. Read the complete blog.\"\/>\r\n<meta name=twitter:title content=\"How to Send Mail in Gmail Account Using ASP.Net? | NTSPL\"\/>"},"_links":{"self":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/536"}],"collection":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/comments?post=536"}],"version-history":[{"count":9,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions"}],"predecessor-version":[{"id":4365,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions\/4365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media\/1487"}],"wp:attachment":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media?parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/categories?post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/tags?post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}