-
Notifications
You must be signed in to change notification settings - Fork 2
Mail Utilities
Aaron edited this page Apr 6, 2017
·
6 revisions
Mail code is something you will have to rewrite on almost every application you work on. I've found it to be much more productive to just stick this in my utilities library and reuse it.
var botMail = new Botmail
{
Addressees = new[] { "[email protected]" },
Addresser = "***@***.**",
Subject = "Test subject",
Body = "Test body",
Ssl = true
};
await Mailbot.GetInstance("mail.google.com").QueueMail(botMail);
Mailbot
wants you to use an encrypted string in your config file for your SMTP passwords. Because storing cleartext
passwords in your config files is a bad idea.
- Create a test project and make a call to
Crypt.HideSecretPassword()
using the same byte array used in the Mailbot class. - Store the resulting encrypted password in the config file called
devlord.utilities.json
, set to "Copy If Newer" in your csproj. This way you don't end up storing your pw in cleartext. For more documentation on encryption see the Encryption page.
// devlord.utilities.json
"devlord.utilities" : {
"SmtpServer" : "",
"SmtpLogin" : "",
"SmtpPassword" : "" // encrypted!
"SmtpPort" : ""
}
One of the most fun features is the ability to throttle your mail sender in case you are worried about hitting limits and getting blacklisted. The default settings below are based on old numbers from Gmail/Google Apps, so you might need to do research to see which settings you would want to use.
MinuteThrottle = new MailThrottle { Interval = ThrottleInterval.Minute, Limit = 180 };
HourlyThrottle = new MailThrottle { Interval = ThrottleInterval.Hour, Limit = 3600 };
DailyThrottle = new MailThrottle { Interval = ThrottleInterval.Day, Limit = 10000 };
These settings are used by default in Mailbot.QueueMail()
.