-
Notifications
You must be signed in to change notification settings - Fork 0
NSG.Library.EMail
The namespace contains a class for emailing via SMTP or SendGrid or Mailgun (Mailgun is untested). This requires an ILogger. NSG.Library.Logger has the default. Also needs NSG.Library.Helpers for reading the appSettings. Finally, it needs the following appSettings (see the tests):
- Email:Enabled
- Email:TestEmailName
- Email:UseService
- Email:ApiKey
- Email:MailgunDomain
A fluent interface for smtp mail message. Example:
new EMail( from, to, "Subject", "Body").Send()
This is an implementation of ILogging. Errors are loggged to the ILogger during the sending of email.
Instantiate the SMTP MailMessage class using the four parameters. This sample shows how to call this constructor.
IEMail _mail = new EMail("[email protected]", "[email protected]", "Sending email is Fun", "This is a test email.").Send();
From email address
To email address
Email subject line
Email body
IEMail to allow fluent design.
Instantiate the SMTP MailMessage class using the four parameters. This sample shows how to call this constructor:
IEMail _mail = new EMail(Log.Logger, "[email protected]", "[email protected]", "Sending email is Fun", "This is a test email.").Send();
This injects an implementation of ILogging from NSG.Library.Logger
From email address
To email address
Email subject line
Email body
IEMail to allow fluent design.
Instantiate the SMTP MailMessage class using no parameters. This sample shows how to call this constructor.
MailAddress _from = new MailAddress("[email protected]", "Example From User"); MailAddress _to = new MailAddress("[email protected]", "Example To User"); string _subject = "Sending email is fun"; string _text = "This is a test email."; IEMail _mail = new EMail().From(_from).To(_to).Subject(_subject).Body(_text).Send();
IEMail to allow fluent design.
Instantiate the SMTP MailMessage class using one parameter of logging. This sample shows how to call this constructor.
MailAddress _from = new MailAddress("[email protected]", "Example From User"); MailAddress _to = new MailAddress("[email protected]", "Example To User"); string _subject = "Sending email is fun"; string _text = "This is a test email."; IEMail _mail = new EMail(Log.Logger).From(_from).To(_to).Subject(_subject).Body(_text).Send();
This injects an implementation of ILogging from NSG.Library.Logger
IEMail to allow fluent design.
Given and EMail instance, start a new email message by instantiating a new SMTP MailMessage class without parameters.
the from email address
the from email address
the subject line
the message body
return its self
Given and EMail instance, start a new email message by instantiating a new SMTP MailMessage class without parameters.
return its self
Set the single from address
string of an email address
itself, IEMail to allow fluent design.
Set the single from email address
string of an email address
display name of the email address
itself, IEMail to allow fluent design.
Set the single from email address
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a To email address.
an email address
return its self
Add a to email address.
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a to email address.
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a carbon copy (cc) email address.
an email address
return its self
Add a carbon copy (cc) email address.
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a carbon copy (cc) email address.
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a blind carbon copy (bcc) email address.
an email address
return its self
Add a blind carbon copy (bcc) email address.
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a blind carbon copy (bcc) email address.
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Set the title of email message.
the subject line
return its self
Set the body of the email message.
Email body
return its self
Is the mail message body Html
true ot false, is body Html
itself, IEMail to allow fluent design.
Add an attachment to the mail message. This sample shows how to call this constructor.
IEMail _mail = new EMail("[email protected]", "[email protected]", "Sending email is Fun", "This is a test email.") .Attachment(_textBuffer, _textFile, _textMimeType).Send();
byte buffer containing the attachment
name placed on the attachment
mime type like 'application/pdf'
return its self
Use appropriate EMail to send out the message/attachments. After sending clean-up the attachments and the streams and finally the mail-message.
return its self
Use MMPA.Library.EMailing to send out the message/attachments. After sending clean-up the attachments and the streams and finally the mail-message.
return its self
Get the current MailMessage
the current MailMessage
retrurn the last few log messages...
Count of last log records to return
list of strings
Output the list of string of the last max emails sent
list of strings
Naturally and automatically dispose of mail-message resource.
Format a string of the current mail message
formated string of a mail message
Format and SMTP MailAddress structure to a string
SMTP MailAddress
string like Phil Huhn [email protected]
Write the current email to a list of string
Property to override the default MailGun URL.
Translate from MailMessage to MultipartFormDataContent.
MultipartFormDataContent (see unit test)
Send the email and any attachments, via the MailGun async task. Note: this was not tested (did not have an account).
The MailGun api key.
Your domain defined with MailGun.
itself, IEMail to allow fluent design.
llamda method to move MailAddress email address to a new SendGrid EmailAddress address.
a MailAddress email address
a new SendGrid EmailAddress address
llamda method to move SendGrid EmailAddress email address to a new MS SMTP MailAddress address.
a SendGrid EmailAddress email address
a new MS SMTP MailAddress address
Translate from MailMessage to SendGridMessage.
a new SendGrid SendGridMessage message found in SendGrid.Helpers.Mail
Convert a SendGridMessage mail message, and load it into a new message. This sample shows how to call the NewMailMessage method.
// translate the message from json string of SendGrid message type JavaScriptSerializer j = new JavaScriptSerializer(); SendGridMessage _sgm = (SendGridMessage)j.Deserialize(_jsonString, typeof(SendGridMessage)); IEMail _email = new EMail(Log.Logger).NewMailMessage(_sgm).Send();
a SendGridMessage mail message from SendGrid.Helpers.Mail
itself, IEMail to allow fluent design.
Send the email and any attachments, via the SendGrid async task.
The SendGrid api key
itself, IEMail to allow fluent design.
Send the email and any attachments, via the SMTP.
itself, IEMail to allow fluent design.
Send the email and any attachments, via the SMTP async task. After sending clean-up the attachments and the streams and finally the mail-message.
itself, IEMail to allow fluent design.
The <see cref="N:NSG.Library.EMail"></see> namespace contains a class for emailing via SMTP or SendGrid or Mailgun (Mailgun is untested). This requires an ILogger. NSG.Library.Logger has the default. Also needs NSG.Library.Helpers for reading the appSettings. Finally, it needs the following appSettings (see the tests):
- production,
- Email:Enabled
- Email:TestEmailName,
- Email:UseService,
- Email:ApiKey,
- Email:MailgunDomain.
Instantiate the SMTP MailMessage class using the four parameters.
From email address
To email address
Email subject line
Email body
IEMail to allow fluent design.
Instantiate the SMTP MailMessage class without parameters.
IEMail to allow fluent design.
Load a SendGridMessage mail message into this message This sample shows how to call the NewMailMessage method.
// translate the message from json string of SendGrid message type JavaScriptSerializer j = new JavaScriptSerializer(); SendGridMessage _sgm = (SendGridMessage)j.Deserialize(_jsonString, typeof(SendGridMessage)); IEMail _email = new EMail(Log.Logger).NewMailMessage(_sgm).Send();
a SendGridMessage mail message
IEMail to allow fluent design.
Get the current MailMessage
the current MailMessage
Set the single from email address
an email address
itself, IEMail to allow fluent design.
Set the single from email address
an email address
display name of the email address
itself, IEMail to allow fluent design.
Set the single from email address
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a to email address.
an email address
itself, IEMail to allow fluent design.
Add a to email address.
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a to email address.
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a carbon copy (cc) email address
an email address
itself, IEMail to allow fluent design.
Add a carbon copy (cc) email address
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a carbon copy (cc) email address
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Add a blind carbon copy (bcc) email address
an email address
itself, IEMail to allow fluent design.
Add a blind carbon copy (bcc) email address
an email address
display name of the email address
itself, IEMail to allow fluent design.
Add a blind carbon copy (bcc) email address
A MailAddress, including an email address and the name
itself, IEMail to allow fluent design.
Set the email subject line
Email subject line
itself, IEMail to allow fluent design.
Set the email body/text.
Email body
itself, IEMail to allow fluent design.
Is the mail message body Html
true ot false, is body Html
itself, IEMail to allow fluent design.
Set an email attachment.
byte array of the file to attach
file name of the attachment
mime type of the attachment
itself, IEMail to allow fluent design.
Send the email and any attachments, via the means defined in the appSetting:
- Email:UseService.
itself, IEMail to allow fluent design.
Use MMPA.Library.EMailing to send out the message/attachments. After sending clean-up the attachments and the streams and finally the mail-message.
return its self
Send the email and any attachments, via the SMTP.
itself, IEMail to allow fluent design.
Send the email and any attachments, via the SMTP async task.
itself, IEMail to allow fluent design.
Translate from MailMessage to SendGridMessage.
SendGridMessage
Send the email and any attachments, via the SendGrid async task.
The SendGrid api key
itself, IEMail to allow fluent design.
Property to override the default MailGun URL.
Translate from MailMessage to MultipartFormDataContent.
MultipartFormDataContent (see unit test)
Send the email and any attachments, via the MailGun async task. Note: this was not tested (did not have an account).
The MailGun api key.
Your domain defined with MailGun.
itself, IEMail to allow fluent design.
retrurn the last few log messages...
Count of last log records to return
list of strings
Output a list of string of the last # of emails sent
list of strings