'Blazor MailKit Email Template
I have a Calculator and i use the following to send the results by email
public void SendEmail()
{
emailbody = "<i>Dear, " + model.FullName;
emailbody = emailbody + "<br>";
emailbody = emailbody + "<br><i>Here are the results using Dromon's Bureau of Shipping EEXI Calulator for: " + model.VesselName + " with IMO Number: </i>" + model.IMONumber;
emailbody = emailbody + "<br><br>";
emailbody = emailbody + "<hr>";
emailbody = emailbody + "<br><b>Full Name: </b>" + model.FullName;
emailbody = emailbody + "<br><b>Email Adsress: </b>" + model.EmailAddress;
emailbody = emailbody + "<br><b>ISM Manager: </b>" + model.ISMManager;
emailbody = emailbody + "<br><b>Vessel Name: </b>" + model.VesselName;
emailbody = emailbody + "<br><b>IMO Number: </b>" + model.IMONumber;
emailbody = emailbody + "<br><b>Type of Vessel: </b>" + model.TypeOfVessel;
emailbody = emailbody + "<br><b>Gross Tonnage: </b>" + model.GrossTonnage;
emailbody = emailbody + "<br><b>Year of built: </b>" + model.YearOfBuilt;
emailbody = emailbody + "<br>";
emailbody = emailbody + "<br><b>Dame and time of Calculation: </b>" + @DateTime.Now;
emailbody = emailbody + "<br><b>EEXI Value: </b>" + eexi;
emailbody = emailbody + "<br><b>Compliance with EEXI regulation: </b>" + Convert.ToString(model.Compliance);
emailbody = emailbody + "<br><br>";
emailbody = emailbody + "<hr>";
emailbody = emailbody + "<br><i>Thank you for using Dromon's Bureau of Shipping EEXI Calculator.";
emailbody = emailbody + "<br><small>This message was sent from an unmonitored address. Please do not respond to this message. Send all inquiries to [email protected]";
email.From.Add(MailboxAddress.Parse("******"));
email.To.Add(MailboxAddress.Parse(model.EmailAddress));
email.Bcc.Add(MailboxAddress.Parse("******"));
email.Subject = "Dromon Bureau of Shipping EEXI calculation Results for IMO Number: " + model.IMONumber;
email.Body = new TextPart(TextFormat.Html) { Text = emailbody };
using var smtp = new SmtpClient();
smtp.Connect("mail.******.com", 587, SecureSocketOptions.StartTls);
smtp.Authenticate("******", "******");
smtp.Send(email);
smtp.Disconnect(true);
}
}
And the result email is:
Now I would like to make the email body an HTML template so it looks more professional and binds the model values similar to what I have now. Please note that I cannot bind values on another page.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

