Click or drag to resize

OutputEmailDeviceSendGridScriptTemplate Field

Default script template for SendGrid

Namespace: Seal.Model
Assembly: SealLibrary (in SealLibrary.dll) Version: 8.3.0.0+c4d725cbae26375217e6c77c92a07fffaea6377d
Syntax
C#
public const string SendGridScriptTemplate = "@using System.IO\r\n@using SendGrid\r\n@using SendGrid.Helpers.Mail\r\n\r\n@{\r\n    OutputEmailDevice.EmailDefinition def = Model;\r\n    var device = def.device;\r\n\r\n\tvar sendGridClient = new SendGridClient(device.ClearSendGridKey);\r\n\r\n    //Create message\r\n\tvar msg = new SendGridMessage()\r\n\t{\r\n\t\tFrom = new EmailAddress(def.sender),\r\n\t\tSubject = def.subject,\r\n\t\tPlainTextContent = def.isHtmlBody ? "" : def.body,\r\n\t\tHtmlContent = !def.isHtmlBody ? "" : def.body,\r\n\t\tReplyTo = new EmailAddress(def.replyTo)\r\n\t};\r\n\r\n\tmsg.SetSubject(def.subject);\r\n\tforeach (var addr in Helper.GetEmailAddresses(def.to)) msg.AddTo(addr);\r\n\tforeach (var addr in Helper.GetEmailAddresses(def.cc)) msg.AddCc(addr);\r\n\tforeach (var addr in Helper.GetEmailAddresses(def.bcc)) msg.AddBcc(addr);\r\n\r\n\tif (!string.IsNullOrEmpty(def.attachPath))\r\n\t{\r\n\t\tvar bytes = File.ReadAllBytes(def.attachPath);\r\n\t\tvar file = Convert.ToBase64String(bytes);\r\n\t\tmsg.AddAttachment(def.attachName, file);\r\n\t}\r\n\r\n    //Send message\r\n\tvar response = sendGridClient.SendEmailAsync(msg).Result;\r\n    \r\n\tif (!response.IsSuccessStatusCode) {\r\n        throw new Exception($"Error sending Email through SendGrid to {def.to}\r\n{response.Body.ReadAsStringAsync().Result}.");\r\n    }\r\n}\r\n"

Field Value

String
See Also