使用MVC Razoor View发送电子邮件 [英] Send Email using MVC Razoor View

查看:41
本文介绍了使用MVC Razoor View发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的初学者,必须实现在MVC应用程序中发送邮件的功能。

I am beginner to MVC, have to implement a functionality to send mail in a MVC application.

是我的代码。

查看:

@using(@ Html.BeginForm())

{



@ Html.TextBoxFor(m => m.EmailID)



< input type =" submit" ;命名= QUOT;名称"值= QUOT;&的SendMail QUOT; />
$
@ {Html.RenderAction(" SendMail"," PagesController");

}

@using (@Html.BeginForm())
{

@Html.TextBoxFor(m => m.EmailID)

<input type="submit" name="name" value="SendMail" />
@{ Html.RenderAction("SendMail", "PagesController");
}

控制器代码:PagesController

Controller code : PagesController

  &NBSP; &NBSP; &NBSP; [HttpPost]

  &NBSP; &NBSP; &NBSP;公共ActionResult SendMail(EmailModel型号)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MailMessage msg = new MailMessage();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; msg.From =新邮件地址(" abc@abc.com");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; msg.To.Add(model.EmailID);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; msg.Subject ="欢迎来到REBAR Mobile Showcase"; $
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; msg.Body ="" + Environment.NewLine + @"欢迎来到REBAR Mobile Showcase。请点击以下链接:https://ciouishowcase.accenture.com/mobile/m"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; + Environment.NewLine +"问候," + Environment.NewLine +" CIO Design Agency";
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; msg.Priority = MailPriority.Normal;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SmtpClient客户端=新的SmtpClient();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.Credentials = new NetworkCredential("abc","passwrod","Dir");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.Host =" email.abc.com";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.Port = 587;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.DeliveryMethod = SmtpDeliveryMethod.Network;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.EnableSsl = true;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.UseDefaultCredentials = true;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; client.Send(msg);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看();

  &NBSP; &NBSP; &NBSP; }

        [HttpPost]
        public ActionResult SendMail(EmailModel model)
        {
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress("abc@abc.com");
            msg.To.Add(model.EmailID);
            msg.Subject = "Welcome To REBAR Mobile Showcase";
            msg.Body = "Hi," + Environment.NewLine + @"Welcome to REBAR Mobile Showcase. Please click on the below link : https://ciouishowcase.accenture.com/mobile/m"
                + Environment.NewLine + "Regards," + Environment.NewLine + "CIO Design Agency";
            msg.Priority = MailPriority.Normal;

            SmtpClient client = new SmtpClient();

            client.Credentials = new NetworkCredential("abc", "passwrod", "Dir");
            client.Host = "email.abc.com";
            client.Port = 587;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.UseDefaultCredentials = true;
            client.Send(msg);
            return View();
        }

型号:EmailModel

Model : EmailModel

我在这里有几个问题:

1。如何在点击发送链接按钮时调用此方法。

1. How should I call this method on click of send link button.

2。我想在文本框和文本框中应用样式。 sendmail链接。我应该如何使用这些类型的控件?

2. I want to apply style as well on the text box & sendmail link. How should I do it with these type of controls?

@ Html.TextBoxFor(m => m.EmailID)

@Html.TextBoxFor(m => m.EmailID)

3。我遵循MVC标准吗?如果不是,那么。

3. Am I following MVC Standards? If not, where.

推荐答案

嗨Arti,

感谢您在MSDN上发帖论坛。

Thank you for posting in the MSDN forum.

根据您的描述,我担心这不是解决此问题的正确论坛。由于此问题与ASP.net有关,您可以将此问题发布在
http://forums.asp.net asp.net专家居住的地方,你会得到专门的回应。

Based on your description, I’m afraid that it is not the correct forum for this issue. Since this issue is related to ASP.net, you could post this issue in http://forums.asp.net where asp.net experts live in, and there you would get dedicated response.

http://forums.asp.net/1146.aspx/1?MVC

祝你好运,


这篇关于使用MVC Razoor View发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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