在Asp.Net MVC Razor中将HTML视图作为电子邮件附件发送 - javascript

我目前在Razor ASP.Net MVC工作。在这里,我有一个HTML view,名为“客户付款”,它是根据某些计算在RAZOR中生成的,并显示在HTML dialog中。

在Asp.Net MVC Razor中将HTML视图作为电子邮件附件发送 - javascript

我想将此Html View作为电子邮件附件发送。但是在这里,我感到困惑,我不得不将这个HTML View转移到.PDF or .jpg中的某些jQuery中,然后将其发送到Controller端,或者是否存在一些更有效的方法来做到这一点。

我仍然有coded可以在C#中发送没有任何附件的简单电子邮件,但此刻被卡住了。

最好的建议将不胜感激。 🙂

javascript参考方案

作为普通邮件,您必须发送如下邮件内容的正文

您的C#代码。

string _FilePath = HttpContext.Server.MapPath("Activation.txt");
StreamReader sr = new StreamReader(_FilePath);
string body = sr.ReadToEnd();
sr.Close();
sr.Dispose();

在电子邮件正文中发送上述正文

您的Activation.txt文件代码将是一个模板,就像下面的body标签一样

<body style="margin: 1% 10%;">
    <table style="position:relative;background-color: whitesmoke;padding-bottom: 20px;text-align: center;width: 100%;">

        <tbody class="">
            <tr class="">
                <td style="position:relative;top:20px;padding-left: 25px;padding-right: 25px;margin-right: auto;margin-left: auto;" width="400" align="center" bgcolor="whiteSmoke">



                    <img src="[HLINK]" height="70" width="150" alt="image cannot displayed ">

                </td>
            </tr>


            <tr>
                <td width="400" align="center" bgcolor="whiteSmoke"></td>
            </tr>

            <tr>
                <td align="center" style="position: relative; top: 11px; padding-left: 25px; padding-right: 25px; margin-right: auto; margin-left: auto;" width="470" bgcolor="whitesmoke">
                    <h2 style="
    color:#f44336;
    font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif">
                        Hey thanks for joining<h2 /> <h4 style="font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;">Welcome to Portal! Before you get started, please verify your email address below </h4>
                </td>
            </tr>

            <tr bgcolor="whitesmoke" style="position:relative;top:9px;">
                <td align="center" style="position:relative;top:-4px;padding-left: 25px;padding-right: 25px;margin-right: auto;margin-left: auto;">

                    <a style="position:relative;display: block;width:150px;height: 20px;text-align:center; text-decoration:none;background:#f44336;padding:10px;border-radius: 5px;color: white;font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;" href="[HLink]">Verify Email Address</a>
                </td>
            </tr>


            <tr>
                <td style="position:relative;top:3px;padding-left: 25px;padding-right: 25px;margin-right: auto;margin-left: auto;" bgcolor="whitesmoke" align="center" width="400">
                    <span style="padding-left:0.3cm;font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;">Thank you for visiting Us. It is the ultimate gift of choice.You can send to a friend or loved one with a selection of brands to pick from in various categories such as fashion, beauty, sports, food, entertainment etc. <span>
                </td>
            </tr>


            <tr>


                <td style="position:relative;padding-left: 25px;padding-right: 25px;margin-right: auto;margin-left: auto;" bgcolor="whitesmoke">
                    <h2 style="color:#f44336;font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;" align="center">Our Most Celebrated Brands</h2>



            </tr>
            <tr>
                <td style="position:relative;top:-2px;padding-left: 25px;padding-right: 25px;margin-right: auto;margin-left: auto;" align="center" bgcolor="whitesmoke" width="400" style="padding:10px;">

                    <b style="font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;">Contact Us:</b>&nbsp;&nbsp;&nbsp;<img src="http://img/phone.png">&nbsp;&nbsp;<span>987654321</span>&nbsp;&nbsp;<img src="http://img/email.jpg">&nbsp;&nbsp;<span styl="font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;">[email protected]</span>
                </td>
            </tr>
            <tr>
                <td style="background-color:whitesmoke;position:relative;text-align: center;">
    <span>
        <a style="position:relative;padding:10px 30px;text-align:center; text-decoration:none;background:#4e69a2;border-radius: 5px;color: white;font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;" href="#">Facebook</a>

        &nbsp;&nbsp;
        <a style="position:relative;padding:10px 30px;text-align:center;text-decoration:none;background:#c32f10;border-radius: 5px;color: white;font-family: WeblySleek UI,Segoe UI,Helvetica Neue,Arial,sans-serif;" href="#">Google</a>
    </span>
</td>
            </tr>
        </tbody>
    </table>  
</body>

您还可以动态添加/替换要通过电子邮件发送的数据
在后端添加以下代码

  body = body.Replace("[HLink]", YOUR-DATA);

在ASP.NET WebForms中在服务器端初始化bootsrap datatimepicker - javascript

我有这个HTML<div class='datepicker input-group date' id='datetimepickerStart'> <input type='text' class="form-control" /> <span c…

在JavaScript中运行方法C# - javascript

打扰一下,我有这种C#asp方法。受保护的无效btnSave_Click(对象发送者,EventArgs e)有谁知道我该如何发送脚本给您?可以办到?。 javascript大神给出的解决方案 是的,那可以做到。为此,您在.aspx.cs页中创建了函数,然后单击保存按钮上的代码将其复制到函数中,然后执行以下步骤。//Call cs method from J…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

在asp.net中使用jQuery做一些ajax - c#

我能够在asp.net中做非常基本的jquery ajax。但是我陷入了困境。请参见下图。由于此对话框具有文件上载控件,因此我无法弄清楚如何将数据发布到服务器并执行正确的操作。我什至感到困惑,我将如何在服务器端获取文件。在正常情况下(回传一),我们可以使用FileUpload1.PostedFile.InputStream 但是,当我打算使用[WebMeth…

编码JSON数据以保留json格式 - javascript

由于JSON值是动态生成的,并且其中的值是基于用户输入的,因此,如果用户在字符串中输入了不可接受的字符(如"),则会使json无效。就像是:{ "tag" : "demo", "value": "user " input" } 有没有一种方法可以编码或转义JS…