If you would like to setup a custom email alias for you or your company, please check out this link first:
Custom Email Aliases
This article will go over how to setup SMTP for an automatic email generator.
If I am doing this for a client company, I will first setup their Custom Email Alias (with the link above).
I will setup a wildcard for their domain pointing all emails to their inbox...
However, I will also create a "contact" alias pointing to my own inbox, that way I can setup the Email Alias myself and attach it to my own account.
I will verify this new "contact" email on my Gmail account and set it as NOT an alias.
I will also hardcode all "to" values to my email address.
I will then test their SMTP, test my code to generate an email from their domain, and test their contact form, before finally deleting the "contact" alias
which will switch everything back over to the client's inbox, and finally changing any "to" values in the code from my email address to their inbox.
That is really the main point of the article, however, I will also include some sample C# code on how I do this:
using (var SmtpServer = new SmtpClient("smtp.gmail.com"))
var mail = new MailMessage
From = from,
Subject = subject,
IsBodyHtml = true,
Body = htmlBody,
// Adjust the Reply To
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.Credentials = new NetworkCredential("firstname.lastname@example.org", Password);
SmtpServer.EnableSsl = true;
EmailRetryAttempts = 0;
If this article helped you, or you have any thoughts on how to do this better, please click the Like button and/or leave a comment below.