string wwwRootPath = _webHostEnvironment.WebRootPath;
string imagePath = Path.Combine(wwwRootPath, "images", "HappyBirthdayCard.jpeg");
if (!File.Exists(imagePath))
{
throw new FileNotFoundException($"File not found at {imagePath}");
}
LinkedResource imageResource = new(imagePath, MediaTypeNames.Image.Jpeg)
{
ContentId = "birthdayImage",
};
string htmlBody = $@"
<p>Dear aa,</p>
<p>Happy Birthday, aa ๐ We send you our warmest wishes on this special day.</p>
<p>Wishing you a very Happy Birthday and all the best on your special day. Enjoy this day to the fullest โจ</p>
<p><img src=""cid:birthdayImage"" alt=""Happy Birthday!"" width=""300""/></p>
<p>Best Regards,</p>
<p><strong>ABC</strong>;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
htmlView.LinkedResources.Add(imageResource);
var mail = new MailMessage
{
Subject = $"Happy Birthday aa! ๐",
IsBodyHtml = true,
Body = htmlBody,
};
mail.AlternateViews.Add(htmlView);
mail.To.Add("aaaaa");
await mailService.SendMailAsync(mail);
string wwwRootPath = _webHostEnvironment.WebRootPath;
string imagePath = Path.Combine(wwwRootPath, "images", "HappyBirthdayCard.jpeg");
if (!File.Exists(imagePath))
{
throw new FileNotFoundException($"File not found at {imagePath}");
}
LinkedResource imageResource = new(imagePath, MediaTypeNames.Image.Jpeg)
{
ContentId = "birthdayImage",
};
string htmlBody = $@"
<p>Dear aa,</p>
<p>Happy Birthday, aa ๐ We send you our warmest wishes on this special day.</p>
<p>Wishing you a very Happy Birthday and all the best on your special day. Enjoy this day to the fullest โจ</p>
<p><img src=""cid:birthdayImage"" alt=""Happy Birthday!"" width=""300""/></p>
<p>Best Regards,</p>
<p><strong>ABC</strong>;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
htmlView.LinkedResources.Add(imageResource);
var mail = new MailMessage
{
Subject = $"Happy Birthday aa! ๐",
IsBodyHtml = true,
Body = htmlBody,
};
mail.AlternateViews.Add(htmlView);
mail.To.Add("aaaaa");
await mailService.SendMailAsync(mail);