如何从asp.net发送邮件,代码.. [英] how to send mail from asp.net, code..

查看:104
本文介绍了如何从asp.net发送邮件,代码..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的代码是发送邮件正文是:



错误是发送邮件失败.......



here this code is to send mail body is :
""""""""""""""""""""""""""""""""""""""""""""""""""""""
ERROR IS FAILURE SENDING MAIL.......
""""""""""""""""""""""""""""""""""""""""""""""""

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Globalization;
using System.Net;
using System.IO;
using System.Xml.Linq;
using System.Net.Mail;


public partial class emergency : System.Web.UI.Page
{
    string gMailAccount = "xxxxxxx@gmail.com";
    string password = "xxxxxxx";
    string to;
    string subject = "Welcome to scalabe and secure personal health records.";
    string message;
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["phr"]);
    string sta = "read",keey="null";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into emergency values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','"+sta+"','"+keey+"')", con);
        cmd.ExecuteNonQuery();
        if(TextBox1.Text!=null&&TextBox2.Text!=null&&TextBox3.Text!=null)
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(gMailAccount);
            message.Subject = "This is the Subject line";
            message.From = new System.Net.Mail.MailAddress("yyyyyyyyyyyy@gmail.com");
            message.Body = "This is the message body";
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
            smtp.Send(message);
              MsgBox.Show("secret key send to ur mail id");
        }
        con.Close();

    }
}

推荐答案

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



您将获得完整的工作代码。



注意 - 请不要发布你问题中的邮件ID和密码。删除那些,否则你可能会收到垃圾邮件。
Refer my previous answer sending email to gmail from asp.net[^].

You will get the full working code.

Note - Please don't post the mail id and password in your question. Delete those, otherwise you might get spam mails.


检查出来: use-csharp-in-aspnet-to-perform-sending-email [ ^ ]



asp.net.web-pages.tutorials.email和搜索/ 11-添加电子邮件到你的Web站点 [ ^ ]
Check this out: use-csharp-in-aspnet-to-perform-sending-email[^]
or
asp.net.web-pages.tutorials.email-and-search/11-adding-email-to-your-web-site[^]


更多参考资料



http://asp.net-tutorials.com/misc/sending-mails/ [ ^ ]



< a href =http://www.aspdotnet-suresh.com/2010/11/introduction-this-article-i-will.html> asp.net中的邮件发送 [ ^ ]
More references

http://asp.net-tutorials.com/misc/sending-mails/[^]

Mail Sending in asp.net[^]


这篇关于如何从asp.net发送邮件,代码..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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