使用MVC后的Gmail收件箱视图

时间:2016-06-29 10:30:24

标签: c# angularjs asp.net-mvc email asp.net-mvc-5

我有创建MVC5项目。在项目部分有电子邮件发送。我已完成电子邮件发送到Gmail收件箱。我想使用MVC显示收件箱gmail。我有以下代码使用电子邮件发送

public ActionResult ContactUs(MailModel objModelMail, HttpPostedFileBase fileUploader)
{
    if (ModelState.IsValid)
    {
        string from = "Email"; //example:- sourabh9303@gmail.com
        using (MailMessage mail = new MailMessage(from, objModelMail.To))
        {
            mail.Subject = objModelMail.Subject;
            mail.Body = objModelMail.Body;
            if (fileUploader != null)
            {
                string fileName = Path.GetFileName(fileUploader.FileName);
                mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
            }
            mail.IsBodyHtml = false;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            NetworkCredential networkCredential = new NetworkCredential(from, "password");
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = networkCredential;
            smtp.Port = 587;
            smtp.Send(mail);
            ViewBag.Message = "Sent";
            return View("ContactUs", objModelMail);
        }
    }
    else
    {
        return View();
    }
}

我的查看代码电子邮件发送

<div class="mail-box">

    @using (@Html.BeginForm("ContactUs", "ContactUs", FormMethod.Post, new { @id = "form1", @enctype = "multipart/form-data" }))
    {
        <div class="mail-body">

            <form class="form-horizontal" method="get">
                <div class="form-group">
                    <label class="col-sm-2 control-label">To:</label>
                    <div class="col-sm-10"> <input type="text" name="To" class="form-control" placeholder="Enter your Email Here"></div>
                </div>
                <br />

                <div class="form-group">
                    <label class="col-sm-2 control-label">Subject:</label>
                    <div class="col-sm-10"> <input type="text" name="Subject" class="form-control" placeholder="Enter Subject Here"></div>
                </div>
                <br/>
                <br/>
                <br />

                @*@Html.TextBoxFor(m => m.Subject)*@

                <div class="form-group">
                    <label class="col-sm-2 control-label">Attachment:</label>

                    <input type="file" name="fileUploader" />
                </div>
            </form>

            <div class="mail-text h-200">
                <div class="summernote">


                    @Html.TextAreaFor(m => m.Body, new { @class = "form-control", style = "width: 840px; height: 139px;" })

                    <br />
                    <br />

                </div>
                <div class="clearfix"></div>
            </div>

            <div class="mail-body text-right tooltip-demo">
                @Html.ValidationSummary()
                <input type="submit" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top" value="Send" />


            </div>

        </div>
    }
</div>

发送电子邮件后如何显示收件箱?提前谢谢

0 个答案:

没有答案