使用邮件消息的HTML邮件内容 [英] HTML Mail Content using Mail message

查看:95
本文介绍了使用邮件消息的HTML邮件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试发送一封包含HTML标签作为邮件正文的邮件,这是我写的功能。

Hi,

I am trying to send a mail which has HTML tags as mail body and this is the function i have written .

private void SendMail(string EmailIDs, string EmailSubject, string EmailBody)
       {
           string strSMTPServer = "Server Address";
           string strSMTPFrom = "Sender Address";

           MailMessage mailMessage = new MailMessage(strSMTPFrom, EmailIDs);
           mailMessage.Subject = EmailSubject;
           mailMessage.Body = EmailBody;
           mailMessage.IsBodyHtml = true;
           SmtpClient smtpClient = new SmtpClient(strSMTPServer);
           smtpClient.Send(mailMessage);
       }





这不起作用,因为包含HTML标签的主体仅显示为标签。



所以我也尝试了这样吗







This is not working as the body that contains HTML tags are shown as tags only.

So i tried like this also


private void SendMail(string EmailIDs, string EmailSubject, string EmailBody)
       {
           string strSMTPServer = "Server Address";
           string strSMTPFrom = "Sender Address";
           MailMessage mailMessage = new MailMessage(strSMTPFrom, EmailIDs);
           mailMessage.Subject = EmailSubject;
           mailMessage.Body = EmailBody;
           mailMessage.IsBodyHtml = true;
           AlternateView av = AlternateView.CreateAlternateViewFromString(EmailBody,      null, MediaTypeNames.Text.Html);
           mailMessage.AlternateViews.Add(av);

           SmtpClient smtpClient = new SmtpClient(strSMTPServer);
           smtpClient.Send(mailMessage);
       }





这也是行不通的。



html支持是否取决于其他因素?任何人都可以帮我解决



And this too is not working.

Does the html support depends on anyother factors? Can anyone please help me out

推荐答案

MailMessage mail = new MailMessage();

SmtpClient SmtpServer = new SmtpClient();

SmtpServer.UseDefaultCredentials = false;

SmtpServer.Credentials = new System.Net.NetworkCredential(NOTIFICATION_MAIL,MAIL_PASSWORD);

SmtpServer.Port = 587;

SmtpServer.EnableSsl = true;

SmtpServer.Host =smtp.gmail.com;

mail.From = new MailAddress(NOTIFICATION_MAIL) ;

mail.To.Add(ToADDRESS_MAIL);

mail.Subject = mailSubject;

mail.Body = messageBody;

SmtpServer.Send(mail);
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(NOTIFICATION_MAIL, MAIL_PASSWORD);
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.Host = "smtp.gmail.com";
mail.From = new MailAddress(NOTIFICATION_MAIL);
mail.To.Add(ToADDRESS_MAIL);
mail.Subject = mailSubject;
mail.Body = messageBody;
SmtpServer.Send(mail);


这篇关于使用邮件消息的HTML邮件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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