Loads and sets email properties from the application configuration file.
The following appSettings can be set in your configuration file, and aspNetEmail will automatically read them, and set the related EmailMessage properties.
| Key Value | Related aspNetEmail.EmailMessage Property/Method |
|---|---|
| EmailMessage.Bcc | Bcc |
| EmailMessage.Body | Body |
| EmailMessage.BodyFormat | BodyFormat (html or text) |
| EmailMessage.Cc | Cc |
| EmailMessage.CharSet | CharSet |
| EmailMessage.ConfirmRead | ConfirmRead |
| EmailMessage.ContentTransferEncoding | EmailMessage.ContentTransferEncoding |
| EmailMessage.FromName | EmailMessage.FromName |
| EmailMessage.FromAddress | EmailMessage.FromAddress |
| EmailMessage.IgnoreRecipientErrors | EmailMessage.IgnoreRecipientErrors |
| EmailMessage.LogBody | EmailMessage.LogBody |
| EmailMessage.Logging | EmailMessage.Logging |
| EmailMessage.LogInMemory | EmailMessage.LogInMemory |
| EmailMessage.LogOverwrite | EmailMessage.LogOverwrite |
| EmailMessage.LogPath | EmailMessage.LogPath |
| EmailMessage.Password | EmailMessage.Passowrd |
| EmailMessage.Priority | EmailMessage.Priority |
| EmailMessage.ReturnReceipt | EmailMessage.ReturnReceipt |
| EmailMessage.Server | EmailMessage.Server |
| EmailMessage.Subject | EmailMessage.Subject |
| EmailMessage.ThrowException | EmailMessage.ThrowException |
| EmailMessage.To | EmailMessage.To |
| EmailMessage.Username | EmailMessage.Username |
| EmailMessage.AttachmentPath | Loads an attachment using EmailMessage.AddAttachment( string FilePathAndName ) |
| EmailMessage.AppendbodyFromFile | Appends the body of the email from a file. Same as using EmailMessage.AppendBodyFromFile( string FilePathAndName ) |
| EmailMessage.AppendBodyFromUrl | Appends the body of the email from a Url. Same as using EmailMessage.AppendbodyFromUrl( string Url, bool FollowRedirects, bool AutoEmbedImages ). By default FollowRedirect = true and AutoEmbedImages = false |
[C#]
With the following web.config settings
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="EmailMessage.To" value="you@yourcompany.com"></add>
<add key="EmailMessage.FromAddress" value="me@mycompany.com"></add>
<add key="EmailMessage.Server" value="mail.mycompany.com"></add>
<add key="EmailMessage.Subject" value="this email sent from the web.config"></add>
<add key="EmailMessage.BodyFormat" value="html"></add>
<add key="EmailMessage.Body" value="<b>this is my bold email sent from the web.config</b>" />
</appSettings>
<system.web>
</system.web>
</configuration>
and calling
EmailMessage msg = new EmailMessage();
msg.LoadFromConfig();
would be the same as setting each of the individual properties:
EmailMessage msg = new EmailMessage();
msg.Server = "mail.mycompany.com";
msg.To = "you@yourcompany.com";
msg.FromAddress = "me@mycompany.com";
msg.Subject = "this email sent from the web.config";
msg.BodyFormat = MailFormat.Html;
msg.Body = "<b>this is my bold email sent from the web.config</b>";
Other properties of the EmailMessage object could be set, or the email could simply be sent.
[Visual Basic]
With the following web.config settings
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="EmailMessage.To" value="you@yourcompany.com"></add>
<add key="EmailMessage.FromAddress" value="me@mycompany.com"></add>
<add key="EmailMessage.Server" value="mail.mycompany.com"></add>
<add key="EmailMessage.Subject" value="this email sent from the web.config"></add>
<add key="EmailMessage.BodyFormat" value="html"></add>
<add key="EmailMessage.Body" value="<b>this is my bold email sent from the web.config</b>" />
</appSettings>
<system.web>
</system.web>
</configuration>
and calling
Dim msg As New EmailMessage()
msg.LoadFromConfig()
'would be the same as setting each of the individual properties:
Dim msg As New EmailMessage()
msg.Server = "mail.mycompany.com"
msg.To = "you@yourcompany.com"
msg.FromAddress = "me@mycompany.com"
msg.Subject = "this email sent from the web.config"
msg.BodyFormat = MailFormat.Html
msg.Body = "<b>this is my bold email sent from the web.config</b>"
EmailMessage Class | aspNetEmail Namespace | EmailMessage.LoadFromConfig Overload List