Specifies a file to load the alternate body of the message from.
A string that contains the fully qualified pathname that the body of the message is loaded from.
If the file does not exist, an error will be returned and processing will stop. If the message body is not HTML, then the setting this property will have no effect because the message body will override the alternate body.
[C#]
public void Send()
{
SmtpServer oSmtpDotNet = new SmtpServer();
// Set the remote server name. If left blank, "localhost" is used.
oSmtpDotNet.ServerAddress = "mail.domain.com";
// Message Addressing
oSmtpDotNet.ToAddress = "to@domain.com";
oSmtpDotNet.FromAddress = "from@domain.com";
// Set the message subject and body
oSmtpDotNet.Body = "This is the message";
oSmtpDotNet.Subject = "Routine email";
// Set the alternate message body to the contents (html) found
// in the file C:\\temp\\body.txt
oSmtpDotNet.AltBodyFile = "C:\\temp\\body.txt";
ReturnCodes nRC = oSmtpDotNet.Send();
if ( nRC != ReturnCodes.SUCCESS )
{
Console.WriteLine("Error #"+nRC+" occurred.");
Console.WriteLine(oSmtpDotNet.LastError);
Console.Write(oSmtpDotNet.LogFileToString(false));
return;
}
// Success!
Console.WriteLine("Success!");
}
[VB]
Public Function Send() As Integer
Dim oSmtpDotNet As New SmtpServer()
Dim nRC As ReturnCodes
' Set the remote server name. If left blank, "localhost" is used.
oSmtpDotNet.ServerAddress = "mail.domain.com"
' Message Addressing
oSmtpDotNet.FromAddress = "from@domain.com"
oSmtpDotNet.ToAddress = "to@domain.com"
' Set the message subject and body
oSmtpDotNet.Subject = "Routine email"
oSmtpDotNet.Body = "This is a briefing of the financials"
' Set the alternate message body to the contents (html) found
' in the file C:\temp\body.txt
oSmtpDotNet.AltBodyFile = "C:\temp\body.txt"
' Send the message. Get the return code and store it in the variable
' nRC. Then check nRC for success or failure
nRC = oSmtpDotNet.Send()
If (nRC <> ReturnCodes.SUCCESS) Then
' A problem occurred.
' Write out the last error encountered
Console.WriteLine(oSmtpDotNet.LastError)
' Write out the log file contents
Console.WriteLine(oSmtpDotNet.LogFileToString(False))
Exit Function
End If
' Success!
Console.WriteLine("Message Sent!")
End Function
SmtpServer Class | SmtpServer Members | SmtpDotNet Namespace