如何通过电子邮件发送HTML页面. [英] how can send a html page through email.

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

问题描述

我可以通过电子邮件发送HTML页面吗?
我在下面发送代码.下面的代码是我要编写html代码的库文件.

can i send a html page through email.
i am send code below.below code is the library file where i m thing write the html code.

namespace MedicalApp.Library
{
    public class SendMail
    {
        public int SendeMail(string company, string empcode, string fromaddress, string toaddress, string subject, string detail, string operation, string username)
        {
            Library lib = new Library();
            int sEmailSend = 0;
            try
            {
                MailMessage objMailMessage = new MailMessage();
                objMailMessage.To.Add(toaddress);
                objMailMessage.From = new MailAddress(fromaddress);
                objMailMessage.Subject = subject;
                objMailMessage.Body = CreateBody(detail, operation, username);
                objMailMessage.IsBodyHtml = true;
                string sSmtpIp = lib.getSmtpIp(company);
                string[] sSmtpIpArr = sSmtpIp.Split(',');
                string sIp = "";
                int iPort = 0;
                if (sSmtpIpArr.Length == 2)
                {
                    sIp = Convert.ToString(sSmtpIpArr[0]);
                    iPort = Convert.ToInt32(sSmtpIpArr[1]);
                }

                SmtpClient objSmtp = new SmtpClient(sIp, iPort);
                objSmtp.Send(objMailMessage);
                sEmailSend = 1;
            }
            catch (Exception ex)
            {
                sEmailSend = 0;
            }
            return sEmailSend;
        }
public string CreateBody(string detail, string operation, string username)
        {




我想在这里写html代码....
CreateBody(详细信息,操作,用户名)




i would like to write html code here....
CreateBody(detail, operation, username)

推荐答案

好了,您已经设置了

objMailMessage.IsBodyHtml = true;

下一步就是使用.body属性,然后将ur html作为字符串值填写到该属性中.

objMailMessage.Body = HTML内容"


例如:

well, u''ve set

objMailMessage.IsBodyHtml = true;

the next step is simply to use the .body property, and fill out ur html as a string value into this property.

objMailMessage.Body = HTML content"


for example :

Mail.Body = "Name : " + txtName.Text + "<br /><br /> "
            Mail.Body += "Organization : " + txtOrg.Text + " <br /><br />"
            Mail.Body += "Email : " + txtEmail.Text + " <br /><br />"



邮件是我的mailMessage对象.



where Mail is my mailMessage object.


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

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