Table of contents
- Note:
- Installation
- API
- Methods
- bool ValidateEmailAddress(string emailAddress);
- bool ValidateEmailAddress(IEnumerable<string> emailAddress);
- ResponseData SendEmail(IEnumerable<string> toAddress, IEnumerable<string> ccAddress, string subject, string body);
- ResponseData SendEmail(IEnumerable<string> toAddress, IEnumerable<string> ccAddress, string subject, string body, IEnumerable<Attachment> attachFiles);
A .NET Standard library which help you easily work with smtp email
Note:
If you are using gmail for smtp server and can't send mail because google block it. Follow these steps:
#Goto
#Then enable
Installation
https://www.nuget.org/packages/EasySmtpEmail
Install-Package EasySmtpEmail
API
using EasyEmail;
Methods
bool ValidateEmailAddress(string emailAddress);
Validate an email address. It must be follow these rules: Has only one @ character. Has at least 3 chars after the @. Domain section contains at least one dot. Dot can't be immediately after the @ character.
Parameters Return Example
bool isValid = EmailHelper.ValidateEmailAddress("youremail@gmail.com");
Assert.AreEqual(true, isValid);
bool ValidateEmailAddress(IEnumerable<string> emailAddress);
Validate list email address
Parameters Return Example
List<string> listEmail = new List<string>
{
"abc@gmail.com", "12.34@123", "12@123.23", "12@123.23.21"
};
bool isValid = EmailHelper.ValidateEmailAddress(listEmail);
Assert.AreEqual(false, isValid);
ResponseData SendEmail(IEnumerable<string> toAddress, IEnumerable<string> ccAddress, string subject, string body);
Send an email without attach files
Parameters Return Example
EmailOptions emailOptions = new EmailOptions
{
SmtpEmailAccount = "your_SmtpEmailAccount",
SmtpPassword = "your_SmtpPassword",
SmtpServer = "smtp.gmail.com",
SmtpPort = 587,
SmtpSsl = true,
SmtpSentFrom = "your_SmtpSentFrom",
SmtpDisplayName = "anything you want"
};
//if it not set => throw exception. (Init one time)
EmailHelper.InitSmtpEmail(emailOptions);
List<string> listToEmail = new List<string>
{
"email1@gmail.com",
"email2@gmail.com"
};
List<string> listCCEmail = new List<string>();
EmailHelper.SendEmail(listToEmail, listCCEmail, "subjectEmail", "bodyEmail");
ResponseData SendEmail(IEnumerable<string> toAddress, IEnumerable<string> ccAddress, string subject, string body, IEnumerable<Attachment> attachFiles);
Send an email with attach files
Parameters Return Example
EmailOptions emailOptions = new EmailOptions
{
SmtpEmailAccount = "your_SmtpEmailAccount",
SmtpPassword = "your_SmtpPassword",
SmtpServer = "smtp.gmail.com",
SmtpPort = 587,
SmtpSsl = true,
SmtpSentFrom = "your_SmtpSentFrom",
SmtpDisplayName = "anything you want"
};
//if it not set => throw exception. (Init one time)
EmailHelper.InitSmtpEmail(emailOptions);
List<string> listToEmail = new List<string>
{
"email1@gmail.com",
"email2@gmail.com"
};
List<string> listCCEmail = new List<string>();
List<Attachment> attachFiles = new List<Attachment>();
attachFiles.Add(new Attachment("/Volumes/UserData/ReadMe.txt"));
EmailHelper.SendEmail(listToEmail, listCCEmail, "subjectEmail", "bodyEmail", attachFiles);