0

I have to place a simple image along with hyperlink inside email body. To send email I am using SendGrid API.

My C# code:

public async Task SendEmailAsync(EmailDeliveryModel model) {
    var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
    var client = new SendGridClient(ConfigurationManager.AppSettings[CommonObject.SendGridKey]);
    var msg = new SendGridMessage();
    msg.SetFrom(new EmailAddress(model.SourceEmail));
    var recipients = new List();
    //multiple recipients
    foreach(string emailAddress in model.DestinationEmail.Trim(',').Split(',')) {
        recipients.Add(new EmailAddress(emailAddress.Trim()));
    }
    msg.AddTos(recipients);
    msg.SetSubject(model.Subject);
    if (model.ContentType.Equals(CommonObject.ContHTML, StringComparison.OrdinalIgnoreCase)) {
        msg.AddContent(MimeType.Html, model.EmailContent + "\n \n \n \n \n");
    } else {
        msg.AddContent(MimeType.Html, model.EmailContent + "\n \n \n \n \n");
    }
    var sendGridresponse = await client.SendEmailAsync(msg);
    if (sendGridresponse.StatusCode == System.Net.HttpStatusCode.Accepted) {
        response.StatusCode = System.Net.HttpStatusCode.OK;
    }
    return response;
}

Inside EmailContent I am injecting html content along with SVG, But SVG is not rendering inside email. But if I am trying the same html in browser it works.

How to send image along with hyper link inside email body?

James Z
  • 12,209
  • 10
  • 24
  • 44
GauravSingh
  • 1,955
  • 1
  • 12
  • 11

0 Answers0