如何使用MVC发送自动电子邮件 [英] How to send automatic emails using MVC

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

问题描述





如何将电子邮件自动发送到gmail,yahoo或hotmail?

其实当我刷新页面时粗略电子邮件将发送到所需的电子邮件地址。

没有按钮我想在这个过程中使用,如从或或只是想发送电子邮件刷新链接。

i尝试过以下代码,但它不起作用。

这里是我的控制器:



Hi,

how i can send email automatically to gmail, yahoo or hotmail?
Actually when i Refresh the page a rough email will send to desired email address.
No buttons i want to use in this process like from or To but just want to send email Refresh the link.
i have tried below code but it doesn't work.
here is my controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.Net.Mail;
using automatic_email.Models;
using Comfirm.AlphaMail;

namespace automatic_email.Controllers
{
    public class emailController : Controller
    {
        // GET: email
        public ActionResult Page_load()
        {
            //MailMessage mailMessage = new System.Net.Mail.MailMessage();
            //mailMessage.To.Add("my email");
            //mailMessage.CC.Add("someone email");
            //mailMessage.Subject = "Some subject";
            //mailMessage.Body = "Some text";

            //using (var smtpClient = new SmtpClient())
            //{
            //    smtpClient.Send(mailMessage);
            //}
            GMailer.GmailUsername = "my email";
            GMailer.GmailPassword = "my password";

            GMailer mailer = new GMailer();
            mailer.ToEmail = "my email";
            mailer.Subject = "Verify your email id";
            mailer.Body = "Thanks for Registering your account.<br> please verify your email id by clicking the link <br> <a href='youraccount.com/verifycode=12323232'>verify</a>";
            mailer.IsHtml = true;
            try
            {
                mailer.Send();
            }
            catch (Exception ex)
            {
                ViewBag.data = ex.ToString();
            }
            return View();
        }
    }
    
}





我尝试过:



我尝试了不同的方法,但没有成功。



What I have tried:

I have Tried different methods but was unsuccessful to do it.

推荐答案

First ,从代码段中删除您的电子邮件地址。垃圾邮件发送者有机器人梳理网站,包括这个,寻找电子邮件地址。如果你喜欢收到垃圾邮件,那就好吧,把它留在那儿。如果没有,请将其删除。



接下来,MVC没有任何Page_Load事件的概念。我认为你真的需要拿一本关于MVC的书来解决它。



你可以将这段代码放在控制器的Index方法中,它会做你做的事情问。无论您使用哪种框架,发送电子邮件都不会发生变化。
First, remove your email address from the code snippets. Spammers have bots that comb through sites, including this one, looking for email addresses. If you love getting spam, fine, leave it in there. If not, remove it.

Next, MVC doesn't have any concept of a Page_Load event. I think you really need to pickup a book on MVC and work through it.

You could put this code inside the Index method of a controller and it would do what you're asking. Sending an email doesn't change no matter which framework you use.


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

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