Table of Contents

Interface IMailService

Namespace
ToSic.Sxc.Services
Assembly
ToSic.Sxc.dll

Service to send mail messages cross-platform.

Get this service in Razor or WebApi using e.g. GetService

[PublicApi]
public interface IMailService

Remarks

New in 2sxc 12.05

Methods

Create(NoParamOrder, object, object, object, object, object, string, string, bool?, Encoding, object)

Quickly create a MailMessage object for further modification and then sending using Send(MailMessage) If you don't want to modify the resulting object, skip this and use the direct-send method.

MailMessage Create(NoParamOrder noParamOrder = default, object from = null, object to = null, object cc = null, object bcc = null, object replyTo = null, string subject = null, string body = null, bool? isHtml = null, Encoding encoding = null, object attachments = null)

Parameters

noParamOrder NoParamOrder

see Convention: Named Parameters

from object

sender e-mail address in one of the following formats

  • An e-mail string like "info@somwhere.com"
  • An e-mail with name and address like "iJungleboy <ijungleboy@2sxc.org>"
  • A single System.Net.Mail.MailAddress object
to object

Main recipient(s) of the mail in one of the following formats

  • all the formats as available in from
  • a CSV of such addresses like "info@a.com, info@b.com"
  • An Array/List/IEnumerable of such strings
  • An Array/List/IEnumerable of System.Net.Mail.MailAddress objects
cc object

CC recipient(s) of the mail, in the same format as to

bcc object

BCC recipient(s) of the mail, in the same format as to

replyTo object

ReplyTo address(es) in the same format as to

subject string

The main subject

body string

The body / contents of the e-mail - can be text or HTML

isHtml bool?

Set the body to be HTML - if not set, will auto-detect

encoding Encoding

Encoding of subject and body - if not set, will default to UTF8. If you need different encodings on subject and body, set it on the resulting object.

attachments object

One or more attachments to include. Could be any of the following

  • A System.Net.Mail.Attachment object
  • An IFile or an IFile object
  • An Array/IEnumerable of these

Returns

MailMessage

The newly created MailMessage object

Send(MailMessage)

Send a .net MailMessage object using the settings configured in Dnn or Oqtane.

void Send(MailMessage message)

Parameters

message MailMessage

A prepared .net MailMessage object

Send(NoParamOrder, object, object, object, object, object, string, string, bool?, Encoding, object)

Quickly create and send an E-Mail.

void Send(NoParamOrder noParamOrder = default, object from = null, object to = null, object cc = null, object bcc = null, object replyTo = null, string subject = null, string body = null, bool? isHtml = null, Encoding encoding = null, object attachments = null)

Parameters

noParamOrder NoParamOrder

see Convention: Named Parameters

from object

sender e-mail address in one of the following formats

  • An e-mail string like "info@somwhere.com"
  • An e-mail with name and address like "iJungleboy <ijungleboy@2sxc.org>"
  • A single System.Net.Mail.MailAddress object
to object

Main recipient(s) of the mail in one of the following formats

  • all the formats as available in from
  • a CSV of such addresses like "info@a.com, info@b.com"
  • An Array/List/IEnumerable of such strings
  • An Array/List/IEnumerable of System.Net.Mail.MailAddress objects
cc object

CC recipient(s) of the mail, in the same format as to

bcc object

BCC recipient(s) of the mail, in the same format as to

replyTo object

ReplyTo address(es) in the same format as to

subject string

The main subject

body string

The body / contents of the e-mail - can be text or HTML

isHtml bool?

Set the body to be HTML - if not set, will auto-detect

encoding Encoding

Encoding of subject and body - if not set, will default to UTF8. If you need different encodings on subject and body, set it on the resulting object.

attachments object

One or more attachments to include. Could be any of the following

  • A System.Net.Mail.Attachment object
  • An IFile or an IFile object
  • An Array/IEnumerable of these