How to set up Google SMTP for NLog config

For a small volume of emails to send as a personal purpose or for a small business, it can be handy to use Google SMTP service as long as you have a Google account. 

It sounds easy task but sometimes it can be tricky if configuration is not properly written and the error message from the Google SMTP is not straightfoward to interpreat what has happened. 

Here is the sample NLog config set up to use Google SMTP. 

<target name="email" xsi:type="Mail"
subject="This is a test Email"
to="[email protected]"
from="[email protected]"
body="${message}${newline}"
smtpUserName="[email protected]"
smtpAuthentication="Basic"
enableSsl="true"
smtpPassword="app password obtain from Google"
smtpServer ="smtp.gmail.com"
smtpPort="465"
/>

Easy enough? 

A few points confused me are

  1. smtpPort should be 465
  2. User name your google email address
  3. Password is Google App Password, which is different from the general Google account password. You can created one following the document

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *