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, MailAddress recipient, 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]",
recipient: new Cake.Email.Common.MailAddress("[email protected]", "Jane Doe"),
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 address of the person sending the email. |
recipient |
MailAddress |
The recipient 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