简体   繁体   English

Blazor MailKit 将值绑定到消息

[英]Blazor MailKit bind values to the message

I have a Blazor server app and I use Mailkit to send emails.我有一个 Blazor 服务器应用程序,我使用 Mailkit 发送电子邮件。 Using a model I bind and send the email to the given address.使用 model 我绑定 email 并将其发送到给定地址。

I have the following code that i use to send emails:我有以下用于发送电子邮件的代码:

    email.To.Add(MailboxAddress.Parse(model.ToEmail));
    email.Subject = "EEXI Calculation Results";
    email.Body = new TextPart(TextFormat.Html) { Text = "Full Name" };

Similarly how I bind the email address using:同样,我如何使用以下方法绑定 email 地址:

email.To.Add(MailboxAddress.Parse(model.ToEmail));

I would like to bind other values from the inputs and show both text我想绑定输入中的其他值并显示两个文本

email.Body = new TextPart(TextFormat.Html) { Text = "Full Name:",model.name};

That's what email templates are used for, there are many ways to create and use them.这就是 email 模板的用途,有很多方法可以创建和使用它们。 Here are some useful links:以下是一些有用的链接:

Custom (simple) string template:自定义(简单)字符串模板:

Create email templates in code... it's very basic, but sometimes that's all you need.在代码中创建 email 模板......这是非常基本的,但有时这就是您所需要的。

public string NewUserEmailTemplate(User user, string confirmationUrl){
    return $"Welcome {user.FirstName} {user.LastName}! You are now a registered user. Please click the following url to confirm your account: {confirmationUrl}";
}

Razor page.cshtml email template Razor page.cshtml email 模板

The more advanced and better way of doing email templates.做 email 模板的更高级和更好的方法。 Here's a link to a tutorial: https://scottsauber.com/2018/07/07/walkthrough-creating-an-html-email-template-with-razor-and-razor-class-libraries-and-rendering-it-from-a-net-standard-class-library/这是教程的链接: https://scottsauber.com/2018/07/07/walkthrough-creating-an-html-email-template-with-razor-and-razor-class-libraries-and-rendering-it -来自网络标准类库/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM