Table of Contents

Class EmailSenderGastroSkySmtp

Namespace
GastroSky.Services.EmailServices.EmailSender
Assembly
GastroSky.dll
public class EmailSenderGastroSkySmtp : IEmailSenderGastroSky
Inheritance
EmailSenderGastroSkySmtp
Implements
Inherited Members

Constructors

EmailSenderGastroSkySmtp(IConfiguration, GastroSkyDatabaseContext, ILogger<EmailSenderGastroSkySmtp>)

public EmailSenderGastroSkySmtp(IConfiguration configuration, GastroSkyDatabaseContext db, ILogger<EmailSenderGastroSkySmtp> logger)

Parameters

configuration IConfiguration
db GastroSkyDatabaseContext
logger ILogger<EmailSenderGastroSkySmtp>

Methods

SendEmailAsync(IEmail)

Method that sends Email Async that accepts a parameter of type IEmail

public Task<bool> SendEmailAsync(IEmail email)

Parameters

email IEmail

IEmail

Returns

Task<bool>

Whether the email has been sent successfully or not.

SendEmailAsync(string, string, string)

Sends a plain-text-only email to a single recipient.

Only use for testing or internal use: html+text variant is much more professional.

The "from" parameter shall be set automatically by the implementing class.
public Task<bool> SendEmailAsync(string subject, string text, string to)

Parameters

subject string

The email's subject.

text string

The email's text body.

to string

The recipient's email address. Please ensure this is valid!

Returns

Task<bool>

Whether the email has been sent successfully or not.

SendEmailAsync(string, string, string, string, string?, IReadOnlyCollection<string>?, IReadOnlyCollection<string>?, IReadOnlyCollection<string>?, IReadOnlyCollection<MailAttachment>?)

Sends an email that contains both a text and html variant. This is the most common approach.

NOTE: even though it is possible to add additional recipients (and CC) it is NOT recommended!

Sending an email to multiple addresses allows all the recipients to see each others' full email addresses.

For the sake of privacy it's recommended to send multiple mails out to single recipients instead (or use BCC, yeah...)
public Task<bool> SendEmailAsync(string from, string to, string subject, string html, string? replyTo = null, IReadOnlyCollection<string>? additionalRecipients = null, IReadOnlyCollection<string>? cc = null, IReadOnlyCollection<string>? bcc = null, IReadOnlyCollection<MailAttachment>? attachments = null)

Parameters

from string

The sender's email address. This can be a raw email address or in the format "Justin Sider <justin.sider@domain.com&gt;".

to string

The recipient email address.

subject string

The mail's subject.

html string

The html email body.

replyTo string

A custom reply-to address. Can be omitted.

additionalRecipients IReadOnlyCollection<string>

Any additional, directly addressed recipients. IMPORTANT: read the doc summary to find out why this is a very bad idea. Use for testing or internal use ONLY!!!

cc IReadOnlyCollection<string>

Carbon copy list.

bcc IReadOnlyCollection<string>

Blind carbon copy list.

attachments IReadOnlyCollection<MailAttachment>

Any email attachments.

Returns

Task<bool>

Whether the email has been sent successfully or not.

SendEmailAsyncInternal(string, string, string, string, string?, IReadOnlyCollection<string>?, IReadOnlyCollection<string>?, IReadOnlyCollection<string>?, IReadOnlyCollection<MailAttachment>?)

public Task<SentEmail?> SendEmailAsyncInternal(string from, string to, string subject, string html, string? replyTo = null, IReadOnlyCollection<string>? additionalRecipients = null, IReadOnlyCollection<string>? cc = null, IReadOnlyCollection<string>? bcc = null, IReadOnlyCollection<MailAttachment>? attachments = null)

Parameters

from string
to string
subject string
html string
replyTo string
additionalRecipients IReadOnlyCollection<string>
cc IReadOnlyCollection<string>
bcc IReadOnlyCollection<string>
attachments IReadOnlyCollection<MailAttachment>

Returns

Task<SentEmail>

SendEmailAsyncWithReturnSentEmail(IEmail)

Method that sends Email Async that accepts a parameter of type IEmail and returns the SentEmail

public Task<SentEmail?> SendEmailAsyncWithReturnSentEmail(IEmail email)

Parameters

email IEmail

IEmail

Returns

Task<SentEmail>

Whether the email has been sent successfully or not.