如何在所需的电子邮件地址上发送电子邮件 [英] how to send e mail on the required e mail address

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

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;// for backgroundworker class
using System.Net;
using System.Net.Mail;

using System.Threading;

namespace ProLogixPOS
{
    public partial class frmForgetPassword : System.Web.UI.Page
    {
        BackgroundWorker bw;
        public void SendMail()
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("ham4159@gmail.com");
            msg.To.Add("aaj_4159@yahoo.com");
            msg.Body = "Testing the automatic mail";
            msg.IsBodyHtml = true;
            msg.Subject = "Movie Data";
            SmtpClient smt = new SmtpClient("smtp.gmail.com");

            smt.Port = 25;
            smt.Credentials = new NetworkCredential("ham4159@gmail.com", "123456789");
            smt.EnableSsl = true;
            smt.UseDefaultCredentials = true;
            smt.Send(msg);
            string script = "<script>alert('Mail Sent Successfully');self.close();</script>";
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "sendMail", script);
        }
       
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SendMail();
          }
    }
}

推荐答案

你做错了。



请参阅我之前的回答从asp.net发送电子邮件到gmail [ ^ ]。



您将获得完整的工作代码。
You are doing it wrong.

Refer my previous answer sending email to gmail from asp.net[^].

You will get the full working code.


您好,因为您正在使用人们在ASP.NET中不再使用的旧C#方法,您需要更新代码,并使用ASP.NET版本的代码。



我写过一篇文章,关于在ASP.NET中发送电子邮件,它关注Gmail帐户。



轻松使用ASP.NET助手发送电子邮件 [< a href =http://www.codeproject.com/Articles/806037/Sending-emails-easily-using-ASP-NET-helperstarget =_ blanktitle =New Window> ^ ]



主要部分是你要连接的端口号,并且连接是安全的,在ASP.NET中你可以使用



Hi, since you're using old methods of C# that people don't use anymore in ASP.NET, you need to update the code, and use the ASP.NET version of the code.

I have written an article, about sending emails in ASP.NET and it focuses the Gmail accounts.

Sending Emails Easily Using ASP.NET Helpers[^]

The major part, is the port number you're connecting through, and that the connection would be secure, in ASP.NET you do that using

WebMail.EnablSsl = true;





..然后继续。阅读文章,它有工作代码示例。您也可以测试它,并且它也解释了使用gmail帐户在ASP.NET中发送电子邮件的基本概念。



..then you continue. Read the article, it has the working code sample. You can test it too, and also it has some explaination of the basic concepts of sending the emails in ASP.NET using gmail accounts.


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

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