ASP.NET身份确认电子邮件是纯文本而不是HTML

编程入门 行业动态 更新时间:2024-10-21 14:22:38
本文介绍了ASP.NET身份确认电子邮件是纯文本而不是HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在ASP.NET MVC5 C#应用程序中,我使用标准代码在用户注册时发送确认电子邮件,这是我在多个项目中所做的事情:

In an ASP.NET MVC5 C# application I am using the standard code for sending confirmation emails when a user registers, something I've done in multiple projects:

var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

通常,收件人在收到电子邮件时,其内容类型为text/html.但是,在此应用程序中,电子邮件带有内容类型的文本/纯文本,并且内容未呈现为html,而是呈现为纯文本.它应该像这样:

Normally when the recipient receives the email, it's content-type is text/html. However, in this one application, the emails arrive with content-type text/plain and the content is not rendered as html, it is rendered as plain text. It should like this:

请点击此处

但它看起来像这样:

Please confirm your account by clicking <a href="localhost:44309/Account/ConfirmEmail?userId=8b126243-1f78-4e42-87d2-ab3c7c350f99&code=tokengoeshere">here</a>

我搜索了文档,但找不到任何信息表明为什么这样做或实际上将如何更改此行为.

I searched the docs but cannot find any information that indicates why this would be or indeed how to change this behavior.

我还更新到了Microsoft ASP.NET Identity Core(2.2.1)的最新版本,认为可能会有所帮助,但它对该问题没有任何影响.

I also updated to the latest version of the Microsoft ASP.NET Identity Core (2.2.1) thinking that might help, but it didn't have any effect on the issue.

我还测试了从其他组织的Google Apps电子邮件帐户发送邮件的情况(我将其用于具有相同代码的其他应用程序来发送此确认电子邮件,并且知道它以html格式发送),以防其中存在某些设置,问题.

I also tested sending from a Google Apps email account for a different organization (which I use for other apps with this exact same code to send this confirmation email and know it sends as html) in case there are some settings in there that matter.

关于为什么它以文本/纯文本形式发送以及如何解决此问题的任何想法?

Any ideas on why it sends as text/plain and how I can fix this?

谢谢!

推荐答案

您使用的邮件服务/api可能存在此问题.我使用了几个,它们通常具有可选的htmlBody参数或isBodyHtml参数.如果您指定使用的是哪种,或者在EmailService类中(在IdentityConfig.cs中)提供SendAsync Methos的代码,则可能很容易将您指示正确的方向.

The issue is likely with the mail service/api you're using. I have used several and they generally have either an optional htmlBody parameter or an isBodyHtml parameter. If you specify which one you're using, or provide the code for the SendAsync Methos in the EmailService class (in IdentityConfig.cs), it'll probably be easy to point you in the right direction.

如果您坚持使用纯文本,则可以发送带有url的纯文本,客户端通常会将其转换为用户的链接. Outlook和gmail可以做到这一点.

If your stuck with plain text, you can send plain text with a url and the client will often convert it into a link for the user. Outlook and gmail do this.

因此,它看起来像这样:

So, it would look like this instead:

await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account:" + callbackUrl);

更多推荐

ASP.NET身份确认电子邮件是纯文本而不是HTML

本文发布于:2023-11-16 09:56:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   文本   电子邮件   身份   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!