使用 SmtpClient 通过 C# 发送 HTML 电子邮件 [英] Send HTML email via C# with SmtpClient

查看:60
本文介绍了使用 SmtpClient 通过 C# 发送 HTML 电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何发送 HTML 电子邮件?我使用这个答案中的代码来使用 SmtpClient 发送电子邮件,但它们始终是纯文本,因此下面示例消息中的链接没有采用这种格式.

How do I send an HTML email? I use the code in this answer to send emails with SmtpClient, but they're always plain text, so the link in the example message below is not formatted as such.

<p>Welcome to SiteName. To activate your account, visit this URL: <a href="http://SiteName.com/a?key=1234">http://SiteName.com/a?key=1234</a>.</p>

如何在我发送的电子邮件中启用 HTML?

How do I enable HTML in the e-mail messages I send?

推荐答案

这就是我所做的:

MailMessage mail = new MailMessage(from, to, subject, message);
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("localhost");
client.Send(mail);

请注意,我将邮件消息 html 设置为 true:mail.IsBodyHtml = true;

Note that I set the mail message html to true: mail.IsBodyHtml = true;

这篇关于使用 SmtpClient 通过 C# 发送 HTML 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆