MailBee.NET Objects 3.1

Smtp.ExecuteCustomCommand Method 

Sends user-defined command to the server and receives the server response to this command.

public bool ExecuteCustomCommand(
   string commandString
);

Parameters

commandString
User-defined command text (including line terminator).

Return Value

true if the command was executed successfully; otherwise, false.

Remarks

The developer can use GetServerResponse method to obtain the response data returned by the server.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample connects to the SMTP server, issues HELP command, and displays the server response to this command. If HELP command is not supported by the server, MailBee will throw MailBeeSmtpNegativeResponseException. It's caught in the sample code, and the proper error message is displayed.

[C#]
// To use the code below, import these namespaces at the top of your code.
using System;
using MailBee;
using MailBee.SmtpMail;

// The actual code (put it into a method of your class)

Smtp mailer = new Smtp();
mailer.SmtpServers.Add("smtp.host.com");
mailer.Connect();
try
{
    // Send HELP command.
    mailer.ExecuteCustomCommand("HELP\r\n");
    Console.WriteLine(mailer.GetServerResponse());
}
catch (MailBeeSmtpNegativeResponseException e)
{
    // The given SMTP server does not support HELP command.
    Console.WriteLine(e.Message);
    Console.WriteLine("Server response is: " + mailer.GetServerResponse());
}
mailer.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.SmtpMail

' The actual code (put it into a method of your class)

Dim mailer As New Smtp
mailer.SmtpServers.Add("smtp.host.com")
mailer.Connect()
Try
    ' Send HELP command.
    mailer.ExecuteCustomCommand("HELP\r\n")
    Console.WriteLine(mailer.GetServerResponse())
Catch e As MailBeeSmtpNegativeResponseException
    ' The given SMTP server does not support HELP command.
    Console.WriteLine(e.Message)
    Console.WriteLine("Server response is: " & mailer.GetServerResponse())
End Try
mailer.Disconnect()

See Also

Smtp Class | MailBee.SmtpMail Namespace