This content is part of a third party extension that is not supported by the Cake project.
For more information about this extension see
Cake.SendGrid.
Summary
Send an email through SendGrid.
Syntax
public SendGridResult SendEmail(string senderName, string senderAddress, IEnumerable<MailAddress> recipients, string subject, string htmlContent, string textContent, IEnumerable<Attachment> attachments, SendGridSettings settings)
Examples
using Cake.Email.Common;
var apiKey = "... your api key ...";
var attachments = new[]
{
Attachment.FromLocalFile("C:\\temp\\MyFile.txt"),
Attachment.FromLocalFile("C:\\temp\\MySpreadsheet.xls"),
Attachment.FromLocalFile("C:\\temp\\MyFile.pdf"),
};
try
{
var result = SendGrid.SendEmail(
senderName: "Bob Smith",
senderAddress: "[email protected]",
recipients: new[] {
new Cake.Email.Common.MailAddress("[email protected]", "Jane Doe"),
new Cake.Email.Common.MailAddress("[email protected]", "John Smith")
},
subject: "This is a test",
htmlContent: "This is a test",
textContent: "This is a test",
attachments: attachments,
settings: new SendGridSettings { ApiKey = apiKey }
);
if (result.Ok)
{
Information("Email successfully sent");
}
else
{
Error("Failed to send email: {0}", result.Error);
}
}
catch(Exception ex)
{
Error("{0}", ex);
}
Attributes
Type |
Description |
CakeAliasCategoryAttribute |
|
Parameters
Name |
Type |
Description |
senderName |
string |
The name of the person sending the email. |
senderAddress |
string |
The email addresses of the person sending the email. |
recipients |
IEnumerable<MailAddress> |
An enumeration of recipients who will receive the email. |
subject |
string |
The subject line of the email. |
htmlContent |
string |
The HTML content. |
textContent |
string |
The text content. |
attachments |
IEnumerable<Attachment> |
Attachments to send with the email. |
settings |
SendGridSettings |
The settings to be used when sending the email. |
Return Value