in src/WebJobs.Extensions.SendGrid/Bindings/SendGridHelpers.cs [50:99]
internal static void DefaultMessageProperties(SendGridMessage mail, SendGridOptions options, SendGridAttribute attribute)
{
// Apply message defaulting
if (mail.From == null)
{
if (!string.IsNullOrEmpty(attribute.From))
{
EmailAddress from = null;
if (!TryParseAddress(attribute.From, out from))
{
throw new ArgumentException("Invalid 'From' address specified");
}
mail.From = from;
}
else if (options.FromAddress != null)
{
mail.From = options.FromAddress;
}
}
if (!IsToValid(mail))
{
if (!string.IsNullOrEmpty(attribute.To))
{
EmailAddress to = null;
if (!TryParseAddress(attribute.To, out to))
{
throw new ArgumentException("Invalid 'To' address specified");
}
mail.AddTo(to);
}
else if (options.ToAddress != null)
{
mail.AddTo(options.ToAddress);
}
}
if (string.IsNullOrEmpty(mail.Subject) &&
!string.IsNullOrEmpty(attribute.Subject))
{
mail.Subject = attribute.Subject;
}
if ((mail.Contents == null || mail.Contents.Count == 0) &&
!string.IsNullOrEmpty(attribute.Text))
{
mail.AddContent("text/plain", attribute.Text);
}
}