MailHelper

Ecng.Net

Provides helper methods to send emails and to manage mail attachments.

メソッド

AddHtml
public static MailMessage AddHtml(MailMessage message, string bodyHtml)
result = MailHelper.AddHtml(message, bodyHtml)

Adds an HTML body alternate view to the specified MailMessage.

message
The mail message to add the HTML body to.
bodyHtml
The HTML string representing the body content.

戻り値: The updated MailMessage instance.

AddPlain
public static MailMessage AddPlain(MailMessage message, string bodyPlain)
result = MailHelper.AddPlain(message, bodyPlain)

Adds a plain text body alternate view to the specified MailMessage.

message
The mail message to add the plain text body to.
bodyPlain
The plain text string representing the body content.

戻り値: The updated MailMessage instance.

Attach
public static MailMessage Attach(MailMessage message, string fileName, Stream fileBody)
result = MailHelper.Attach(message, fileName, fileBody)

Attaches a file to the specified MailMessage using the provided stream.

message
The mail message to attach the file to.
fileName
The name of the file to attach.
fileBody
The stream that represents the file content.

戻り値: The updated MailMessage instance.

CreateAttachment
public static Attachment CreateAttachment(Stream attachmentFile, string displayName, TransferEncoding transferEncoding)
result = MailHelper.CreateAttachment(attachmentFile, displayName, transferEncoding)

Creates an Attachment from the provided stream and display name, with specified transfer encoding.

attachmentFile
The stream containing the attachment file.
displayName
The display name for the attachment.
transferEncoding
The transfer encoding to use. Defaults to Base64.

戻り値: A new instance of Attachment configured with the provided parameters.

EmailRegex
private static Regex EmailRegex()
result = MailHelper.EmailRegex()
IsEmailValid
public static bool IsEmailValid(string email)
result = MailHelper.IsEmailValid(email)

Validates whether the specified email address string is in a correct format.

email
The email address string to validate.

戻り値: true if the email format is valid; otherwise, false.

ToAttachment
public static Attachment ToAttachment(string fileName, Stream fileBody)
result = MailHelper.ToAttachment(fileName, fileBody)

Creates a new Attachment from the specified file name and file stream.

fileName
The name of the file for the attachment.
fileBody
The stream representing the attachment content.

戻り値: A new instance of Attachment.