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

首頁 > 學院 > 開發設計 > 正文

asp.net 發送郵件

2019-11-15 02:31:24
字體:
來源:轉載
供稿:網友

asp.net 發送郵件

crm 需要推送郵件,網上搜了搜----

直接上代碼

mailhelper  -------mail幫助類

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mail;/// <summary>///mailhelper 的摘要說明/// </summary>public class mailhelper{    public mailhelper()    {        //        //TODO: 在此處添加構造函數邏輯        //    }    /// <summary>    /// 郵件發送操作    /// </summary>    /// <param name="Addressee">收件人地址</param>    /// <param name="From">發件人地址</param>    /// <param name="sendpassWord">發件人密碼</param>    /// <param name="Copy">抄送人地址</param>    /// <param name="secret">密送人地址</param>    /// <param name="Subject">發送主題</param>    /// <param name="Attachment">附件信息</param>    /// <param name="Body">郵件內容</param>    public string SendeEmal(string Addressee, string From, string sendpassword, string Copy, string secret, string Subject, string Attachment, string Body)    {        MailMessage objmailMessage;        MailAttachment objMailAttachment;        // 創建郵件消息        objMailMessage = new MailMessage();        //發件人EMAIL        objMailMessage.From = From;//源郵件地址        //收件人EMAIL        objMailMessage.To = Addressee; //目的郵件地址        //郵件抄送        objMailMessage.Cc = Copy;        //郵件misong        objMailMessage.Bcc = secret;        //郵件主題        objMailMessage.Subject = Subject; //發送郵件的標題        //郵件內容        objMailMessage.Body = Body;//發送郵件的內容        // 創建一個附件對象        if (Attachment != "")        {            objMailAttachment = new MailAttachment(Attachment);//發送郵件的附件 c://test.txt            objMailMessage.Attachments.Add(objMailAttachment);//將附件附加到郵件消息對象中        }        //接著利用SMTP來發送郵件,需要使用Microsoft .NET Framework SDK v1.1和它以上的版本        //基本權限        objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");        //用戶名        string name = From.Substring(0, From.IndexOf('@'));        objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", name);        //密碼        objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendpassword);        //如果沒有上述三行代碼,則出現如下錯誤提示:服務器拒絕了一個或多個收件人地址。服務器響應為: 554 : Client host rejected: access denied        //SMTP地址              string smtp = "smtp." + From.Substring(From.IndexOf('@') + 1);        SmtpMail.SmtpServer = "smtp." + From.Substring(From.IndexOf('@') + 1);        //開始發送郵件        try        {            SmtpMail.Send(objMailMessage);            return "郵件發送成功!";        }        catch (System.Net.Mail.SmtpException ex)        {            return ex.Message;        }        //核心代碼結束    }}

然后下來是自己做的一個demo--

前臺:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mail.aspx.cs" Inherits="information_mail"    ValidateRequest="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script src="../Style/jquery/jquery.js" type="text/javascript"></script>    <script src="../Style/jquery/jquery.validate.js" type="text/Javascript"></script>    <script language="javascript" type="text/javascript">        function gei() {            var file_value = document.getElementById("File1").value;            document.getElementById("HiddenField1").value = file_value;        }    </script></head><body>    <form id="form1" runat="server">    <div>        發給:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />        抄送:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />        密送:<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />        主題:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />        內容:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />        附件:<input id="File1" type="file" />        <%--<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>--%>        <br />        <asp:Button ID="Button1" runat="server" Text="發送" OnClientClick="gei()" OnClick="Button1_Click" /><br />        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>    </div>    <asp:HiddenField ID="HiddenField1" runat="server" />    </form></body></html>

后臺:

PRotected void Button1_Click(object sender, EventArgs e)    {                //實例郵件幫助類        mailhelper mails = new mailhelper();        string filePath = HiddenField1.Value;        string a = mails.SendeEmal(TextBox1.Text, "郵件賬號", "郵件密碼", TextBox2.Text, TextBox4.Text, TextBox5.Text, filePath, TextBox3.Text);        Label1.Text = a;    }

知道自己還得再這條路上走,好好積累吧。眨眼


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 图木舒克市| 新巴尔虎左旗| 土默特左旗| 平陆县| 长宁区| 高平市| 永宁县| 屯昌县| 定边县| 沈丘县| 定南县| 桦甸市| 昭通市| 台山市| 玉田县| 马公市| 内江市| 沈阳市| 皮山县| 九台市| 牡丹江市| 濮阳县| 紫阳县| 治县。| 谷城县| 新兴县| 清水河县| 昌邑市| 藁城市| 南康市| 佛学| 和静县| 昌平区| 南通市| 南木林县| 惠州市| 渑池县| 东乡族自治县| 彝良县| 云龙县| 甘洛县|