Class SmtpAppender
Send an e-mail when a specific logging event occurs, typically on errors or fatal errors.
public class SmtpAppender : BufferingAppenderSkeleton, IBulkAppender, IAppender, IOptionHandler
- Inheritance
-
SmtpAppender
- Implements
- Inherited Members
Remarks
The number of logging events delivered in this e-mail depend on the value of BufferSize option. The SmtpAppender keeps only the last BufferSize logging events in its cyclic buffer. This keeps memory requirements at a reasonable level while still delivering useful application context.
caution
Authentication and setting the server Port are only available on the MS .NET 1.1 runtime. For these features to be enabled you need to ensure that you are using a version of the log4net assembly that is built against the MS .NET 1.1 framework and that you are running the your application on the MS .NET 1.1 runtime. On all other platforms only sending unauthenticated messages to a server listening on port 25 (the default) is supported.
Authentication is supported by setting the Authentication property to either Basic or Ntlm. If using Basic authentication then the Username and Password properties must also be set.
To set the SMTP server port use the Port property. The default port is 25.
Constructors
SmtpAppender()
Default constructor
public SmtpAppender()
Remarks
Default constructor
Properties
Authentication
The mode to use to authentication with the SMTP server
public SmtpAppender.SmtpAuthentication Authentication { get; set; }
Property Value
Remarks
caution
Authentication is only available on the MS .NET 1.1 runtime.
Valid Authentication mode values are: None, Basic, and Ntlm. The default value is None. When using Basic you must specify the Username and Password to use to authenticate. When using Ntlm the Windows credentials for the current thread, if impersonating, or the process will be used to authenticate.
Bcc
Gets or sets a semicolon-delimited list of recipient e-mail addresses that will be blind carbon copied.
public string Bcc { get; set; }
Property Value
- string
A semicolon-delimited list of e-mail addresses.
Remarks
A semicolon-delimited list of recipient e-mail addresses.
BodyEncoding
Gets or sets the body encoding to be used.
public Encoding BodyEncoding { get; set; }
Property Value
Remarks
The default encoding is the operating system's current ANSI codepage.
Cc
Gets or sets a comma- or semicolon-delimited list of recipient e-mail addresses that will be carbon copied (use semicolon on .NET 1.1 and comma for later versions).
public string Cc { get; set; }
Property Value
- string
For .NET 1.1 (System.Web.Mail): A semicolon-delimited list of e-mail addresses.
For .NET 2.0 (System.Net.Mail): A comma-delimited list of e-mail addresses.
Remarks
For .NET 1.1 (System.Web.Mail): A semicolon-delimited list of e-mail addresses.
For .NET 2.0 (System.Net.Mail): A comma-delimited list of e-mail addresses.
EnableSsl
Enable or disable use of SSL when sending e-mail message
public bool EnableSsl { get; set; }
Property Value
Remarks
This is available on MS .NET 2.0 runtime and higher
From
Gets or sets the e-mail address of the sender.
public string From { get; set; }
Property Value
- string
The e-mail address of the sender.
Remarks
The e-mail address of the sender.
LocationInfo
Obsolete
[Obsolete("Use the BufferingAppenderSkeleton Fix methods")]
public bool LocationInfo { get; set; }
Property Value
Remarks
Use the BufferingAppenderSkeleton Fix methods instead
Password
The password to use to authenticate with the SMTP server
public string Password { get; set; }
Property Value
Remarks
caution
Authentication is only available on the MS .NET 1.1 runtime.
A Username and Password must be specified when Authentication is set to Basic, otherwise the password will be ignored.
Port
The port on which the SMTP server is listening
public int Port { get; set; }
Property Value
Remarks
caution
Server Port is only available on the MS .NET 1.1 runtime.
The port on which the SMTP server is listening. The default
port is 25. The Port can only be changed when running on
the MS .NET 1.1 runtime.
Priority
Gets or sets the priority of the e-mail message
public MailPriority Priority { get; set; }
Property Value
- MailPriority
One of the MailPriority values.
Remarks
Sets the priority of the e-mails generated by this appender. The default priority is Normal.
If you are using this appender to report errors then you may want to set the priority to High.
ReplyTo
Gets or sets the reply-to e-mail address.
public string ReplyTo { get; set; }
Property Value
Remarks
This is available on MS .NET 2.0 runtime and higher
RequiresLayout
This appender requires a log4net.Layout to be set.
protected override bool RequiresLayout { get; }
Property Value
- bool
true
Remarks
This appender requires a log4net.Layout to be set.
SmtpHost
Gets or sets the name of the SMTP relay mail server to use to send the e-mail messages.
public string SmtpHost { get; set; }
Property Value
- string
The name of the e-mail relay server. If SmtpServer is not set, the name of the local SMTP server is used.
Remarks
The name of the e-mail relay server. If SmtpServer is not set, the name of the local SMTP server is used.
Subject
Gets or sets the subject line of the e-mail message.
public string Subject { get; set; }
Property Value
- string
The subject line of the e-mail message.
Remarks
The subject line of the e-mail message.
SubjectEncoding
Gets or sets the subject encoding to be used.
public Encoding SubjectEncoding { get; set; }
Property Value
Remarks
The default encoding is the operating system's current ANSI codepage.
To
Gets or sets a comma- or semicolon-delimited list of recipient e-mail addresses (use semicolon on .NET 1.1 and comma for later versions).
public string To { get; set; }
Property Value
- string
For .NET 1.1 (System.Web.Mail): A semicolon-delimited list of e-mail addresses.
For .NET 2.0 (System.Net.Mail): A comma-delimited list of e-mail addresses.
Remarks
For .NET 1.1 (System.Web.Mail): A semicolon-delimited list of e-mail addresses.
For .NET 2.0 (System.Net.Mail): A comma-delimited list of e-mail addresses.
Username
The username to use to authenticate with the SMTP server
public string Username { get; set; }
Property Value
Remarks
caution
Authentication is only available on the MS .NET 1.1 runtime.
A Username and Password must be specified when Authentication is set to Basic, otherwise the username will be ignored.
Methods
SendBuffer(LoggingEvent[])
Sends the contents of the cyclic buffer as an e-mail message.
protected override void SendBuffer(LoggingEvent[] events)
Parameters
eventsLoggingEvent[]The logging events to send.
SendEmail(string)
Send the email message
protected virtual void SendEmail(string messageBody)
Parameters
messageBodystringthe body text to include in the mail