我想在mvc.net中使用html模板向用户发送电子邮件

时间:2018-02-26 10:28:40

标签: asp.net-mvc

我想在mvc.net中向html模板的用户发送一封电子邮件我正在尝试绑定html模板,但是简单的邮件模板没有显示,这是我的代码。

这里是控制器代码

 private void SendActivationEmail(AddCenter center)
{
    Guid activationCode = Guid.NewGuid();
     TrueScanEntities db  = new TrueScanEntities();
      db.UserActivations.Add(new UserActivation
    {
        ID = center.Center_ID,
        ActivationLink = activationCode
    });
    db.SaveChanges();

    using (MailMessage mm = new MailMessage("sender@gmail.com", center.Center_Email))
    {
        StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate/EmailTemplate.html"));
        mm.Subject = "Account Credential";
        string body = "Hello " + center.CenterIncharge + ",";
        body += "<br /><br />Your Account Credential is given below" + "<br/>" + "User Name"+":"+"<br/>"+ center.Center_Email+"<br/>"+"Password"+":"+ center.Center_Passwrd + ".";

        //body += "<br /><br />Please click the following link to activate your account";
        //body += "<br /><a href = '" + string.Format("{0}://{1}/Admin/Activation/{2}", Request.Url.Scheme, Request.Url.Authority, activationCode) + "'>Click here to activate your account.</a>";
        body += "<br /><br />Thanks";
        mm.Body = body;
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential("abc@gmail.com", "123");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
    }
}

这是一个HTML模板,我想在给定模板中向用户发送用户ID和密码。

我应该在html模板中做什么?

<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%">
    <tr>
        <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;">
            <center>
                <img src="../ATemplate/assets/images/newly.png" />

            </center>
        </td>
    </tr>
    <tr>
        <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding">
            <center>
                <table cellspacing="0" cellpadding="0" width="600" class="w320">
                    <tr>
                        <td class="header-md">
                            Thank You For Registration <!--In [client]-->
                        </td>
                    </tr>
                    <tr>
                        <td class="free-text">Kindly retain below Registration Details for logging in future.</td>
                    </tr>
                    <tr>
                        <td class="mini-block-container">
                            <table cellspacing="0" cellpadding="0" width="100%" style="border-collapse:separate !important;">
                                <tr>
                                    <td class="mini-block">
                                        <table cellpadding="0" cellspacing="0" width="100%" class="table table-bordered">
                                            <tr>
                                                <th>Name</th>
                                                <td>[name]</td>
                                            </tr>


                                            <tr>
                                                <th>User Name</th>
                                                <td>[user]</td>
                                            </tr>
                                            <tr>
                                                <th>Email ID</th>
                                                <td>[email]</td>
                                            </tr>

                                            <tr>
                                                <th>Password</th>
                                                <td>[pass]</td>
                                            </tr>
                                            <tr>
                                                <th>Reg Date</th>
                                                <td>[date]</td>
                                            </tr>


                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </center>
        </td>
    </tr>
    <tr>
        <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;">
            <center>
                <table cellspacing="0" cellpadding="0" width="600" class="w320">
                    <tr>
                        <td style="padding: 25px 0 25px">
                            <strong>Coppyright </strong><a href="https://www.Whizsoftwares.com" target="_blank"> Whizsoftwares.com</a>
                        </td>
                    </tr>
                </table>
            </center>
        </td>
    </tr>
</table>

邮件是这样发送的:

enter image description here

但我想绑定此模板:

enter image description here

0 个答案:

没有答案