How to configure SMTP settings in web.config

By setting the values <mailSettings> section of the in the web.config you can just new up an SmtpClient and the client will use those settings. https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient.-ctor?view=net-6.0#system-net-mail-smtpclient-ctor Web.Config file: <configuration> <system.net> <mailSettings> <smtp from=”yourmail@gmail.com”> <network host=”smtp.gmail.com” port=”587″ userName=”yourmail@gmail.com” password=”yourpassword” enableSsl=”true”/> </smtp> </mailSettings> </system.net> </configuration> C#: SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(msgMail); However, if authentication is needed, … Read more

Precedence: header in email

There is a RFC 3834 dedicated for automated email responses. In short, it recommends: Send auto-responses only to address contained in the Return-Path header of an incoming message, if it is valid email address. Particularly “<>” (null address) in the Return-Path of the message means that auto-responses must not be sent for this message. When … Read more

Nodemailer/Gmail – What exactly is a refresh token and how do I get one?

Notes by this answer original’s author: So, I finally managed to figure it out. I’m surprised I couldn’t find more ressources about that so for those who need to use Gmail with Nodemailer I found the answer here: http://masashi-k.blogspot.fr/2013/06/sending-mail-with-gmail-using-xoauth2.html Try creating a new User if you already had one and things ain’t working fine. It … Read more

Email model validation with DataAnnotations and DataType

DataType attribute is used for formatting purposes, not for validation. I suggest you use ASP.NET MVC 3 Futures for email validation. Sample code: [Required] [DataType(DataType.EmailAddress)] [EmailAddress] public string Email { get; set; } If you happen to be using .NET Framework 4.5, there’s now a built in EmailAddressAttribute that lives in System.ComponentModel.DataAnnotations.EmailAddressAttribute.