发送评论到我的电子邮件? [英] sending comments to my email ?

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

问题描述

大家好,我希望您没错...我有自己的网站...我是用html创建的.
这是我的问题:我创建了一个文本框和一个按钮,供用户发表自己的评论..
现在我想做的是:当用户放置他的评论并按下按钮时,评论应发送到我的emial ....我该怎么做? >解决方案

使用此代码:

 受保护的 无效 Button1_Click(对象发​​件人,EventArgs e)
{
    System.Net.Mail.MailMessage MailMessage1 =  System.Net.Mail.MailMessage();
    // 在此处添加您的邮件地址:
    MailMessage1.To.Add(" );
    // 在此处添加您的邮件地址:
    MailMessage1.From =  System.Net.Mail.MailAddress(" );
    // 在此处添加您的邮件主题:
    MailMessage1.Subject = " ;
    // 在此处更改您的文本框名称(如果要评论的文本框具有其他名称)
    MailMessage1.Body = TextBox1.Text;
    // 如果您的smtp服务器使用BodyHtml,请更改此部分.
    MailMessage1.IsBodyHtml =  false ;

    System.Net.Mail.SmtpClient SmtpClient1 =  System.Net.Mail.SmtpClient();

    // 指定您的smtp服务器:
    // 更改为您的smtp服务器名称:
    SmtpClient1.Host = " ;
    // 更改为您的smtp服务器端口:
    SmtpClient1.Port =  587 ;
    // 添加您的电子邮件和密码:
    SmtpClient1.Credentials =  System.Net.NetworkCredential("  您的密码");
    // 如果您的smtp服务器未使用SSL,请更改此部分.
    SmtpClient1.EnableSsl =  true ;

    尝试
    {
        SmtpClient1.Send(MailMessage1);
        // 邮件发送成功
        Response.Redirect(" );
    }
    捕获
    {
        // 发送邮件失败
        Response.Redirect(" );
    }
}


Hello all , i hope u r right ... i have my own site ...i created it by html.
and here is my Q: i created a text box and a button for users to put thier comments ..
now i what i want to do is that : when a user put his comment and press on the button ,,the comment should be sent to my emial .... how can i do it ????

解决方案

Use this code:

 protected void Button1_Click(object sender, EventArgs e)
{
    System.Net.Mail.MailMessage MailMessage1 = new System.Net.Mail.MailMessage();
    //Add your mail address here:
    MailMessage1.To.Add("YourMailAdress");
    //Add your mail address here:
    MailMessage1.From = new System.Net.Mail.MailAddress("YourMailAdress");
    //Add your mail subject here:
    MailMessage1.Subject = "Mail Subject";
    //Change you textbox name here(if your textbox for comment has another name)
    MailMessage1.Body = TextBox1.Text;
    //Change this part if your smtp server use BodyHtml.
    MailMessage1.IsBodyHtml = false;

    System.Net.Mail.SmtpClient SmtpClient1 = new System.Net.Mail.SmtpClient();

    //Specify your smtp server:
    //Change to your smtp server name:
    SmtpClient1.Host = "smtp.gmail.com";
    //Change to your smtp server port:
    SmtpClient1.Port = 587;
    //Add your Email and password:
    SmtpClient1.Credentials = new System.Net.NetworkCredential("YourEmail", "Your Password");
    //Change this part if your smtp server do not use SSL.
    SmtpClient1.EnableSsl = true;

    try
    {
        SmtpClient1.Send(MailMessage1);
        //Mail sends successfully
        Response.Redirect("SendMailSuccess.aspx");
    }
    catch
    {
        //Failed to send mail
        Response.Redirect("SendMailFail.aspx");
    }
}


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

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