我正在尝试将邮件模板附加到邮件工具包中,我正在使用.NET Core 这是我的代码
//From Address
string FromAddress = "info@gorollo.com";
string FromAdressTitle = "Gorollo";
//To Address
string ToAddress = email;
string Subject = subject;
string BodyContent = message;
var body = new BodyBuilder();
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress
(FromAdressTitle,
FromAddress
));
mimeMessage.To.Add(new MailboxAddress
(
ToAddress
));
mimeMessage.Subject = Subject;
using (var client = new SmtpClient())
{
client.Connect("smtp.mailgun.org", 587, false);
client.Authenticate(
"info@gorollo.com",
"password"
);
await client.SendAsync(mimeMessage);
await client.DisconnectAsync(true);
}
我看到很多例子,但无法找到确切的解决方案 所以请任何人帮我解决问题 我必须在我的邮件中附上注册模板。
答案 0 :(得分:1)
你几乎在这里。您可以使用BodyBuilder
向正文添加文本或HTML。使用TextBody
或HtmlBody
属性分别设置文本或HTML。使用ToMessageBody()
方法创建一个MimeEntity
实例,您可以将其用作邮件正文。
示例:
var message = new MimeMessage();
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "<h1>Hello, World!</h1>";
message.Body = bodyBuilder.ToMessageBody();