简体   繁体   English

如何使用asp.net C#将HTML格式的电子邮件正文传递给javascript函数

[英]How to pass HTML formatted email body to a javascript function using asp.net c#

Here is the C# part 这是C#部分

for (int i = 0; i <= mailergrd.Rows.Count - 1; i++)
{
    SBEmailBody.Append("<'html><'body><table><tr><td>  Dear  <b> <name>,    </td></tr></table></b>  <br/><br/>  Welcome  <br/>" + "hiii.<br/>"+</body></html>");

    SBEmailBody.Replace("<name>", mailergrd.Rows[i]["Name"].ToString());

    System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(),     "SendMail"+i, "SendMail('TO@syn.com','" + SBEmailBody.ToString() + "','Greetings     from PDAC','CC@syn.com');", true);
}

Here is the JavaScript part 这是JavaScript部分

function SendMail(to,body,sub,cc)
{
    var theApp;  
    var theMailItem;  
    var subject = sub;
    var msg = body;
    var carbon = cc;

try
{
    var theApp = new ActiveXObject("Outlook.Application");        
    var theMailItem = theApp.CreateItem(0);
    theMailItem.To = to;
    theMailItem.Subject = (subject);
    theMailItem.CC = carbon;
    theMailItem.Body = (msg); 
    theMailItem.Display();
 } 

OUTPUT 输出值

<html><body><table><tr><td>  JOHN <b> ,</td></tr></table></b> <br/><br/> Welcome <br/>" + "hiii.<br/>" +</body></html>

I'm trying to send E-Mails from client-side which is working fine except for the body of the mail: its not html formatted while passing from code behind. 我正在尝试从客户端发送电子邮件,除了邮件正文以外,它都工作正常:从背后的代码传递时,其格式不是html格式。

I Think Many Questions Like these have Been Answered Before. 我认为像这样的许多问题已经得到解答。

Return HTML from ASP.NET Web API Have a look at that and See if its a possible Solution. 从ASP.NET Web API返回HTML。看看它是否可行。

您需要将HTML格式的字符串传递给MailItem.HTMLBody属性,而不是.Body。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#在ASP.NET中的JavaScript函数中执行 - How to execute in JavaScript function in ASP.NET using C# 如何通过电子邮件在asp.net c#中发送HTML表单? - How to send an HTML form in asp.net c# by email? 如何在asp.net中使用C#代码将参数传递给JavaScript函数? - How can I use C# code in asp.net to pass a parameter to a JavaScript function? 在ASP.net C#中,如何将参数从Javascript函数传递给onclick处理程序 - In ASP.net C# how do I pass an argument from a Javascript function to the onclick handler 如何使用 c# 或 Z686155AF75A17A0F6E9DED08 在 asp.net 中打开外部网站并获取其 html 内容 - How to open external website and get its html content in asp.net using c# or JavaScript 尝试使用隐藏字段将值从ASP.NET JavaScript脚本传递给我的C#代码隐藏函数 - Trying to pass value from ASP.NET JavaScript script to my C# Code Behind function using Hidden Field asp.net webforms-如何使用C#获取JavaScript函数的json数据 - asp.net webforms - how to get the json data of a javascript function using c# ASP.NET-如何使用C#显示JavaScript警报? - ASP.NET - How to display javascript alert using C#? 如何使用 javascript 调用 ASP.NET c# 方法 - how to call an ASP.NET c# method using javascript 在ASP.NET中使用javascript传递在函数后面调用c#的变量值 - Pass variable value calling c# behind function with javascript in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM