OpenPetra
Free Administration Software for Non-Profits
Ict.Common.IO.TSmtpSender Class Reference

This is a small wrapper around the .net SMTP Email services More...

Inheritance diagram for Ict.Common.IO.TSmtpSender:

Public Member Functions

 TSmtpSender ()
 Set up the SMTP client More...
 
void SetSender (string AAddress, string ADisplayName)
 Sets the sender address for the email - or set of emails. More...
 
void AddAttachment (string ADisplayFileName, string APhysicalFileName)
 add an attachment with a different name to avoid temp names in the email More...
 
MimeMessage GetNewMimeMessage ()
 Returns a new MimeMessage with From, Reply-To and CC addresses set from the values in User Defaults. More...
 
bool SendEmail (string fromemail, string fromDisplayName, string recipients, string subject, string body, string[] attachfiles=null)
 Create a mail message and send it as from the specified sender address. More...
 
bool SendEmailFromTemplate (string fromemail, string fromDisplayName, string recipients, string template, string language, Dictionary< string, string > parameters, string[] attachfiles=null)
 Create a mail message from a language specific template and send it as from the specified sender address. The first line in the template is the subject, all following lines are the body. More...
 
bool SendEmail (string recipients, string subject, string body, string[] attachfiles=null)
 Create a mail message and send it as from the address that has already been set. More...
 
bool SendMessage (MimeMessage AEmail)
 Send an email message More...
 
void Dispose ()
 Dispose of the IDisposable objects used by this object. More...
 

Static Public Member Functions

static TSmtpServerSettings GetSmtpSettingsFromAppSettings ()
 Method to obtain the SMTP email server configuration settings from the configuration file. More...
 
static bool ValidateEmailAddress (string field)
 Static method that can be called from anywhere to validate an email address. More...
 
static List< MailboxAddress > ConvertAddressList (string AList)
 Convert a semicolon-separated list of email addresses to a list of email address objects. More...
 

Static Public Attributes

static readonly String EMAIL_USER_LOGIN_NAME = "IUSROPEMAIL"
 todoComment More...
 
static readonly String SMTP_HOST_DEFAULT = ".example.org"
 The domain of the default dummy SmtpHost written to our Server.config. Used here to check whether SMTP has been configured. More...
 
static readonly string RECENTADDRS = "EmailRecentAddresses"
 User Default code for the list of most recently used email addresses. More...
 

Properties

static TGetSmtpSettings GetSmtpSettings [get, set]
 Client or Server Delegate used to get the SMTP server settings. More...
 
MailboxAddress Sender [get]
 Returns the sender address for use if constructing a MimeMessage outside this class. More...
 
List< TsmtpFailedRecipientFailedRecipients [get]
 After SendMessage, this contains a list of any recipients we failed to send to. More...
 
string ErrorStatus [get]
 An indication of any errors that occurred during SendMessage. More...
 
String CcEverythingTo [set]
 Use this to get all the emails copied to an address More...
 
String BccEverythingTo [set]
 Use this to get all the emails blind copied to an address More...
 
String ReplyTo [set]
 If the ReplyTo address should be different, use this. More...
 

Detailed Description

This is a small wrapper around the .net SMTP Email services

Constructor & Destructor Documentation

◆ TSmtpSender()

Ict.Common.IO.TSmtpSender.TSmtpSender ( )
inline

Set up the SMTP client

Member Function Documentation

◆ AddAttachment()

void Ict.Common.IO.TSmtpSender.AddAttachment ( string  ADisplayFileName,
string  APhysicalFileName 
)
inline

add an attachment with a different name to avoid temp names in the email

◆ ConvertAddressList()

static List< MailboxAddress > Ict.Common.IO.TSmtpSender.ConvertAddressList ( string  AList)
inlinestatic

Convert a semicolon-separated list of email addresses to a list of email address objects.

Where OpenPetra has multiple addresses stored in one database field, most are separated by semicolons because by default Microsoft Outlook requires semicolons to separate addresses (https://blogs.msdn.microsoft.com/oldnewthing/20150119-00/?p=44883). But the Internet, including .NET's MailMessage.To.Add(string) method, requires commas (https://tools.ietf.org/html/rfc5322#section-3.4). So when pulling "To" addresses from the database we must parse them for unquoted semicolons and convert them to commas.

Parameters
AList
Returns

◆ Dispose()

void Ict.Common.IO.TSmtpSender.Dispose ( )
inline

Dispose of the IDisposable objects used by this object.

◆ GetNewMimeMessage()

MimeMessage Ict.Common.IO.TSmtpSender.GetNewMimeMessage ( )
inline

Returns a new MimeMessage with From, Reply-To and CC addresses set from the values in User Defaults.

Returns
A MimeMessage
Exceptions
ESmtpSenderInitializeExceptionThrown if the sender address has not been set.

◆ GetSmtpSettingsFromAppSettings()

static TSmtpServerSettings Ict.Common.IO.TSmtpSender.GetSmtpSettingsFromAppSettings ( )
inlinestatic

Method to obtain the SMTP email server configuration settings from the configuration file.

◆ SendEmail() [1/2]

bool Ict.Common.IO.TSmtpSender.SendEmail ( string  fromemail,
string  fromDisplayName,
string  recipients,
string  subject,
string  body,
string[]  attachfiles = null 
)
inline

Create a mail message and send it as from the specified sender address.

Returns
Flag indicating whether email was sent.
Exceptions
ESmtpSenderInitializeExceptionThrown when the sender address is invalid. An inner exception may contain more detail.

◆ SendEmail() [2/2]

bool Ict.Common.IO.TSmtpSender.SendEmail ( string  recipients,
string  subject,
string  body,
string[]  attachfiles = null 
)
inline

Create a mail message and send it as from the address that has already been set.

The sender address must be set using SetSender(string, string)

Returns
Flag indicating whether email was sent. Check the ErrorStatus property for further details.
Exceptions
ESmtpSenderInitializeExceptionThrown when the sender address is invalid. An inner exception may contain detail.

◆ SendEmailFromTemplate()

bool Ict.Common.IO.TSmtpSender.SendEmailFromTemplate ( string  fromemail,
string  fromDisplayName,
string  recipients,
string  template,
string  language,
Dictionary< string, string >  parameters,
string[]  attachfiles = null 
)
inline

Create a mail message from a language specific template and send it as from the specified sender address. The first line in the template is the subject, all following lines are the body.

Returns
Flag indicating whether email was sent.
Exceptions
ESmtpSenderInitializeExceptionThrown when the sender address is invalid. An inner exception may contain more detail.

◆ SendMessage()

bool Ict.Common.IO.TSmtpSender.SendMessage ( MimeMessage  AEmail)
inline

Send an email message

Parameters
AEmailOn successful sending, the header is modified with the sent date.
Returns
True if email was sent successfully.

◆ SetSender()

void Ict.Common.IO.TSmtpSender.SetSender ( string  AAddress,
string  ADisplayName 
)
inline

Sets the sender address for the email - or set of emails.

Parameters
AAddress
ADisplayName

◆ ValidateEmailAddress()

static bool Ict.Common.IO.TSmtpSender.ValidateEmailAddress ( string  field)
inlinestatic

Static method that can be called from anywhere to validate an email address.

Parameters
field
Returns
True if the string forms a valid email address; false otherwise.

Member Data Documentation

◆ EMAIL_USER_LOGIN_NAME

readonly String Ict.Common.IO.TSmtpSender.EMAIL_USER_LOGIN_NAME = "IUSROPEMAIL"
static

todoComment

◆ RECENTADDRS

readonly string Ict.Common.IO.TSmtpSender.RECENTADDRS = "EmailRecentAddresses"
static

User Default code for the list of most recently used email addresses.

◆ SMTP_HOST_DEFAULT

readonly String Ict.Common.IO.TSmtpSender.SMTP_HOST_DEFAULT = ".example.org"
static

The domain of the default dummy SmtpHost written to our Server.config. Used here to check whether SMTP has been configured.

Property Documentation

◆ BccEverythingTo

String Ict.Common.IO.TSmtpSender.BccEverythingTo
set

Use this to get all the emails blind copied to an address

◆ CcEverythingTo

String Ict.Common.IO.TSmtpSender.CcEverythingTo
set

Use this to get all the emails copied to an address

◆ ErrorStatus

string Ict.Common.IO.TSmtpSender.ErrorStatus
get

An indication of any errors that occurred during SendMessage.

◆ FailedRecipients

List<TsmtpFailedRecipient> Ict.Common.IO.TSmtpSender.FailedRecipients
get

After SendMessage, this contains a list of any recipients we failed to send to.

◆ GetSmtpSettings

TGetSmtpSettings Ict.Common.IO.TSmtpSender.GetSmtpSettings
staticgetset

Client or Server Delegate used to get the SMTP server settings.

◆ ReplyTo

String Ict.Common.IO.TSmtpSender.ReplyTo
set

If the ReplyTo address should be different, use this.

◆ Sender

MailboxAddress Ict.Common.IO.TSmtpSender.Sender
get

Returns the sender address for use if constructing a MimeMessage outside this class.


The documentation for this class was generated from the following file: