国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#發郵件的代碼 (vs2005)

2024-07-21 02:26:06
字體:
來源:轉載
供稿:網友

using system;
using system.data;
using system.configuration;
using system.collections;
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.net;
using system.net.mail;
public partial class sendemail : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {

    }
    protected void button1_click(object sender, eventargs e)
    {

        string s_from = textbox1.text.trim().tostring();
        string s_to = textbox3.text.trim().tostring();
        string pwd=textbox2.text .trim().tostring();
        string s_body =textbox5.text.trim().tostring();
        s_body = s_body.replace("/r/n","<br/>");
        s_body = s_body.replace("/n", "<br/>");
        s_body = s_body.replace(" ", "&nbsp");

        int i = s_from.indexof("@");
        string username = s_from.substring(0,i);


        mailaddress from = new mailaddress(s_from);
        mailaddress to = new mailaddress(s_to);
        mailmessage mailobj = new mailmessage(from ,to);
        mailobj.subject = textbox4.text.trim().tostring();
        mailobj.body = s_body;
        mailobj.isbodyhtml = true;
        mailobj.bodyencoding = system.text.encoding.getencoding("gb2312");
        mailobj.priority = mailpriority.high;

        if (fileupload1.postedfile.contentlength > 0)
        {
            mailobj.attachments.add(new attachment(  fileupload1.postedfile.filename));
        }

        smtpclient smtp = new smtpclient("smtp.163.com");
       // smtp.host = "smtp.163.com";
        smtp.usedefaultcredentials = false;
        smtp.credentials = new networkcredential(username,pwd);
        smtp.deliverymethod = smtpdeliverymethod.network;

        try {
            smtp.send(mailobj);
            response.write("ok!");
       
        }
        catch
       
        {
            response.write("sorry!");
        }
      
       
         }
}

////因為用的郵箱都是163的,所以就設置了smtp的地址是163的地址,如果用別的郵箱,只要smtp的地址改下就可以了.


 

商業源碼熱門下載www.html.org.cn

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江安县| 永城市| 高陵县| 永清县| 东兰县| 平山县| 松阳县| 西畴县| 永寿县| 三江| 张家港市| 荆门市| 辽中县| 文安县| 资源县| 卢氏县| 德保县| 蒙城县| 房山区| 凌云县| 玛沁县| 昆山市| 石河子市| 浏阳市| 馆陶县| 咸宁市| 资中县| 梁平县| 民乐县| 晋城| 正蓝旗| 海晏县| 边坝县| 同仁县| 平乐县| 永春县| 高雄县| 庐江县| 新安县| 调兵山市| 邵阳市|