Smtp.NET 3 Documentation

SmtpServer.Send Method (String, String, String, String)

Send the message.

[Visual Basic]
Overloads Public Function Send( _
   ByVal sToAddress As String, _
   ByVal sFromAddress As String, _
   ByVal sSubject As String, _
   ByVal sBody As String _
) As ReturnCodes
[C#]
public ReturnCodes Send(
   string sToAddress,
   string sFromAddress,
   string sSubject,
   string sBody
);

Parameters

sToAddress
The "to" email address
sFromAddress
The "from" email address
sSubject
The "subject" of the email
sBody
The "body" of the email

Return Value

An enumerated value of ReturnCodes

Remarks

After this method is called, all recipients in the "to", "cc", "bcc" fields are cleared.

Events

Event TypeReason
If DBDataTable is specified, this event will be raised with the percentage complete

See: ProgressEventHandler for a complete example.

Example

[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";
      
     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"

     ' 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

See Also

SmtpServer Class | SmtpServer Members | SmtpDotNet Namespace | SmtpServer.Send Overload List | ReturnCodes | SendQuick