如何发送HTML格式的电子邮件? [英] How to send HTML-formatted email?

查看:103
本文介绍了如何发送HTML格式的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让Web应用程序使用Windows Task Scheduler发送自动电子邮件.现在,我想使用为发送电子邮件编写的以下方法发送HTML格式的电子邮件.

I could be able to let the web application sends automatic emails using Windows Task Scheduler. Now I want to send HTML-Formatted email using the following method that I wrote for sending emails.

我的隐藏代码:

protected void Page_Load(object sender, EventArgs e)
    {
        SmtpClient sc = new SmtpClient("mail address");
        MailMessage msg = null;

        try
        {
            msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system");

             sc.Send(msg);
        }

        catch (Exception ex)
        {
            throw ex;
        }

        finally
        {
            if (msg != null)
            {
                msg.Dispose();
            }
        }
    }

该怎么做?我只想在电子邮件中放一些带有一个链接的粗体文本,也许还有一张图像.

How to do that? I just want to put some bold text with one link and maybe one image in the email.

推荐答案

isBodyHtml设置为true允许您在邮件正文中使用HTML标记:

Setting isBodyHtml to true allows you to use HTML tags in the message body:

msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system<br />" +
                "<b>this is bold text!</b>");

msg.IsBodyHtml = true;

这篇关于如何发送HTML格式的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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