Class SmtpConnector
This class implements the ISmtpConnectable interface and
uses only the System.Net.Mail namespace internally.
Inheritance
Namespace: TeleScope.Connectors.Smtp
Assembly: TeleScope.Connectors.Smtp.dll
Syntax
public class SmtpConnector : object, ISmtpConnectable, IConnectable
Constructors
| Improve this Doc View SourceSmtpConnector(String, Int32, ISecret)
The constructor gets the SMTP host configuration injected.
Declaration
public SmtpConnector(string host, int port, ISecret secret)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | host | The name of the host or server. |
| System.Int32 | port | The port where the SMTP protocol is accessible at the host. |
| ISecret | secret | The user credentials to get access at the host. |
SmtpConnector(SmtpSetup)
The default constructor stores the setup and starts the internal logging mechanism.
Declaration
public SmtpConnector(SmtpSetup setup)
Parameters
| Type | Name | Description |
|---|---|---|
| SmtpSetup | setup | The setup that is used for the smtp connections. |
Properties
| Improve this Doc View SourceIsConnected
Gets the state, if the connection is established or not.
Declaration
public bool IsConnected { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
| Improve this Doc View SourceAttach(FileInfo, String)
This method should attach a file to the latest email.
Declaration
public ISmtpConnectable Attach(FileInfo file, string mimeType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | The file info object that will be attached. |
| System.String | mimeType | The mime type of the file. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
BlindCarbonCopy(String)
Adds a bcc (blind carbon body) address to the last email
that was created by the last call of NewMessage.
Declaration
public ISmtpConnectable BlindCarbonCopy(string to)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | to | The email address of the receiver. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
BlindCarbonCopy(String[])
Adds a bcc (blind carbon body) address to the last email
that was created by the last call of NewMessage.
Declaration
public ISmtpConnectable BlindCarbonCopy(string[] to)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | to | The email addresses of the receivers. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
CarbonCopy(String)
Adds a cc (carbon body) address to the last email
that was created by the last call of NewMessage.
Declaration
public ISmtpConnectable CarbonCopy(string to)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | to | The email address of the receiver. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
CarbonCopy(String[])
Adds a cc (carbon body) address to the last email
that was created by the last call of NewMessage.
Declaration
public ISmtpConnectable CarbonCopy(string[] to)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | to | The email addresses of the receivers. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
Connect()
Clears the internal collection of emails and invokes the Connected event.
Declaration
public ISmtpConnectable Connect()
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | The calling instance. |
Disconnect()
Clears the internal collection of emails and invokes the Disconnected event.
Declaration
public ISmtpConnectable Disconnect()
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | The calling instance. |
HighPriority()
Adds a high priority flag to the latest email.
Declaration
public ISmtpConnectable HighPriority()
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
LowPriority()
Adds a low priority flag to the latest email.
Declaration
public ISmtpConnectable LowPriority()
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
NewMessage(String, String)
Adds a new message to an internal collection of emails with only specific properties, needed to build a new email object. Sender and receivers are known by the implementing instace beforehand.
Declaration
public ISmtpConnectable NewMessage(string subject, string body)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | subject | The subject of the email. |
| System.String | body | The message of the email. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
NewMessage(String, String, String, String)
Adds a new message to an internal collection of emails with the essetial properties, needed to build a new email object.
Declaration
public ISmtpConnectable NewMessage(string from, string to, string subject, string body)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | from | The email address of the sender. |
| System.String | to | The email address of the receiver. |
| System.String | subject | The subject of the email. |
| System.String | body | The message of the email. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
NewMessage(String, String[], String, String)
Adds a new message to an internal collection of emails with the essetial properties, needed to build a new email object.
Declaration
public ISmtpConnectable NewMessage(string from, string[] to, string subject, string body)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | from | The email address of the sender. |
| System.String[] | to | The email addresses of the receivers. |
| System.String | subject | The subject of the email. |
| System.String | body | The message of the email. |
Returns
| Type | Description |
|---|---|
| ISmtpConnectable | Returns the calling instance to enable chaining method calls. |
Send()
Sends all the created and configured emails at once and clears the inner stack. If emails where not sent, those objects are removed internally anyways and the logging provides detailed information.
Declaration
public (int total, int success, int failed) Send()
Returns
| Type | Description |
|---|---|
| System.ValueTuple<System.Int32, System.Int32, System.Int32> | Returns a result triple that contains the total amount of sent emails, the sucessful and the failed ones. |
Events
| Improve this Doc View SourceCompleted
The event is invoked when the Send() method has finished successfully.
Declaration
public event ConnectorCompletedEventHandler Completed
Event Type
| Type | Description |
|---|---|
| ConnectorCompletedEventHandler |
Connected
The event is invoked when the Connect() method has finished successfully.
Declaration
public event ConnectorEventHandler Connected
Event Type
| Type | Description |
|---|---|
| ConnectorEventHandler |
Disconnected
The event is invoked when the Disconnect() method has finished successfully.
Declaration
public event ConnectorEventHandler Disconnected
Event Type
| Type | Description |
|---|---|
| ConnectorEventHandler |
Failed
The event is invoked when the Send() method has finished with a failure.
Declaration
public event ConnectorFailedEventHandler Failed
Event Type
| Type | Description |
|---|---|
| ConnectorFailedEventHandler |