aspNetEmail

EmailMessage.LoadFromConfig Method (Boolean, String)

Loads and sets email properties from the application configuration file.

public void LoadFromConfig(
   bool send,
   string keyPrefix
);

Parameters

send
Send the email, once the settings have been loaded.
keyPrefix
The prefix found on each of the application settings

Remarks

The following appSettings can be set in your configuration file, and aspNetEmail will automatically read them, and set the related EmailMessage properties. By specifing a prefix string, aspNetEmail will override any of the standard settings.

Key ValueRelated aspNetEmail.EmailMessage Property/Method
EmailMessage.BccBcc
EmailMessage.BodyBody
EmailMessage.BodyFormatBodyFormat (html or text)
EmailMessage.CcCc
EmailMessage.CharSetCharSet
EmailMessage.ConfirmReadConfirmRead
EmailMessage.ContentTransferEncodingEmailMessage.ContentTransferEncoding
EmailMessage.FromNameEmailMessage.FromName
EmailMessage.FromAddressEmailMessage.FromAddress
EmailMessage.IgnoreRecipientErrorsEmailMessage.IgnoreRecipientErrors
EmailMessage.LogBodyEmailMessage.LogBody
EmailMessage.LoggingEmailMessage.Logging
EmailMessage.LogInMemoryEmailMessage.LogInMemory
EmailMessage.LogOverwriteEmailMessage.LogOverwrite
EmailMessage.LogPathEmailMessage.LogPath
EmailMessage.PasswordEmailMessage.Passowrd
EmailMessage.PriorityEmailMessage.Priority
EmailMessage.ReturnReceiptEmailMessage.ReturnReceipt
EmailMessage.ServerEmailMessage.Server
EmailMessage.SubjectEmailMessage.Subject
EmailMessage.ThrowExceptionEmailMessage.ThrowException
EmailMessage.ToEmailMessage.To
EmailMessage.UsernameEmailMessage.Username
EmailMessage.AttachmentPathLoads an attachment using EmailMessage.AddAttachment( string FilePathAndName )
EmailMessage.AppendbodyFromFileAppends the body of the email from a file. Same as using EmailMessage.AppendBodyFromFile( string FilePathAndName )
EmailMessage.AppendBodyFromUrlAppends 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

Example

[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>" />
             		<add key="orders_EmailMessage.Subject" value="Use this subject for sending orders"></add>
             	</appSettings>
               <system.web>
              </system.web>
             </configuration>
             
             and calling
             
             EmailMessage msg = new EmailMessage();
             msg.LoadFromConfig( false, "orders_" );
             
             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 = "Use this subject when sending orders.";
             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>" />
             		<add key="orders_EmailMessage.Subject" value="Use this subject for sending orders"></add>
             	</appSettings>
               <system.web>
              </system.web>
             </configuration>
             
             and calling
             Dim msg As New EmailMessage()
             msg.LoadFromConfig( False, "orders_" )
             
             '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 = "Use this subject when sending orders."
             msg.BodyFormat = MailFormat.Html
             msg.Body = "<b>this is my bold email sent from the web.config</b>"
             

See Also

EmailMessage Class | aspNetEmail Namespace | EmailMessage.LoadFromConfig Overload List