MAIL

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;
using System.Net.Mime;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        string file = Server.MapPath("testXML.xml");
        MailMessage myMail = new System.Net.Mail.MailMessage(); ;
        myMail = new System.Net.Mail.MailMessage(txtSender.Text.Trim(), txtReceiver.Text.Trim(),txtSubject.Text.Trim(),txtContent.Text.Trim());
        if (ddlAccessories.Items.Count > 0)
        {
            for (int i = 0; i < ddlAccessories.Items.Count; i++)
            {
                System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(Server.MapPath(ddlAccessories.Items[i].Value), System.Net.Mime.MediaTypeNames.Application.Octet);
                System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
                disposition.CreationDate = System.IO.File.GetCreationTime(file);
                disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
                myMail.Attachments.Add(myAttachment);
            }
        }
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.163.com", 25);
        client.Credentials = new System.Net.NetworkCredential("**", "****");
        client.Send(myMail);
    }
    protected void btnTake_Click(object sender, EventArgs e)
    {
        if (upFile.PostedFile.ContentLength != 0)
        {
            string clientFileName = upFile.PostedFile.FileName;
            string[] strTemp = clientFileName.Split('.');
            string upFileExp = strTemp[strTemp.Length - 1].ToString();
            string ServerFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp;
            upFile.PostedFile.SaveAs(Server.MapPath(ServerFileName));
            ddlAccessories.Items.Add(new ListItem(clientFileName, ServerFileName));
            if (ddlAccessories.Items.Count > 0)
            {
                btnDelete.Enabled = true;
            }
            else
            {
                btnDelete.Enabled = false;
            }
        }
    }
}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <table align="center" cellpadding="0" cellspacing="0" style="width: 755px">
                <tr>
                    <td style="background-image: url(image/标头.jpg); width: 755px; height: 63px; text-align: center">
                    </td>
                </tr>
            </table>
            <table align="center" cellpadding="0" cellspacing="0" style="width: 755px">
                <tr>
                    <td style="font-size: 9pt; background-image: url(image/链接.jpg); width: 755px; color: #ffffff;
                        height: 20px; text-align: right">
                        ◎<asp:HyperLink ID="hpLinkLogin" runat="server" Font-Size="9pt" Font-Underline="False"
                            ForeColor="White" NavigateUrl="~/Login.aspx">重新登录</asp:HyperLink>
                        ◎<asp:HyperLink ID="hpLinkIndex" runat="server" Font-Size="9pt" Font-Underline="False"
                            ForeColor="White" NavigateUrl="~/SendEmail.aspx">返回首页</asp:HyperLink>
                        ◎<asp:LinkButton ID="lbtnGroupEmail" runat="server" Font-Size="9pt" Font-Underline="False"
                            ForeColor="White" >邮件群发</asp:LinkButton>
                        ◎<asp:HyperLink ID="hpLinkAddFriend" runat="server" Font-Size="9pt" Font-Underline="False"
                            ForeColor="White" NavigateUrl="~/AddFriend.aspx">添加好友</asp:HyperLink>
                        ◎<asp:HyperLink ID="hpLinkFriend" runat="server" Font-Size="9pt" Font-Underline="False"
                            ForeColor="White" NavigateUrl="~/FriendInfo.aspx">查看好友</asp:HyperLink>&nbsp;
                        &nbsp; &nbsp;</td>
                </tr>
            </table>
        </div>
        <table align="center" cellpadding="0" cellspacing="0" style="background-image: url(image/内容.jpg);
            width: 755px; height: 410px">
            <tr>
                <td style="width: 176px; background-color: transparent; text-align: center">
                    <asp:Label ID="labReceiver" runat="server" Font-Size="9pt" Text="收件人:"></asp:Label>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtReceiver"
                        ErrorMessage="**"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtReceiver"
                        ErrorMessage="格式不正确" ValidationExpression="/w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*"></asp:RegularExpressionValidator></td>
                <td style="font-size: 12pt; width: 579px; text-align: center" align="left">
                    <asp:TextBox ID="txtReceiver" runat="server" Font-Size="9pt" Width="575px"></asp:TextBox></td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 176px; background-color: transparent; text-align: center">
                    <asp:Label ID="labSender" runat="server" Font-Size="9pt" Text="发件人:"></asp:Label>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtSender"
                        ErrorMessage="**"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtSender"
                        ErrorMessage="格式不正确" ValidationExpression="/w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*"></asp:RegularExpressionValidator></td>
                <td style="width: 579px; text-align: center">
                    <asp:TextBox ID="txtSender" runat="server" Font-Size="9pt" Width="579px"></asp:TextBox></td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 176px; background-color: transparent; text-align: center">
                    <asp:Label ID="labSubject" runat="server" Font-Size="9pt" Text="主题:"></asp:Label>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtSubject"
                        ErrorMessage="**"></asp:RequiredFieldValidator>
                </td>
                <td style="width: 579px; text-align: center">
                    <asp:TextBox ID="txtSubject" runat="server" Font-Size="9pt" Width="579px"></asp:TextBox>
                </td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 176px; background-color: transparent; text-align: center">
                    <asp:Label ID="labContent" runat="server" Font-Size="9pt" Text="内容:"></asp:Label></td>
                <td style="width: 579px; text-align: center">
                    <asp:TextBox ID="txtContent" runat="server" Font-Size="9pt" Height="160px" TextMode="MultiLine"
                        Width="579px"></asp:TextBox></td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 176px; background-color: transparent; text-align: center">
                    <asp:Label ID="labAccessories" runat="server" Font-Size="9pt" Text="附件:"></asp:Label></td>
                <td style="width: 579px; text-align: left">
                    <input id="upFile" runat="server" font-size="9pt" style="width: 534px" type="file" />
                    <asp:Button ID="btnTake" runat="server" Font-Size="9pt" OnClick="btnTake_Click" Text="上传"
                        Width="40px" CausesValidation="False" /></td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 176px; height: 14px; background-color: transparent; text-align: center">
                    <asp:Label ID="labTakeAcc" runat="server" Font-Size="9pt" Text="已上传附件:"></asp:Label></td>
                <td style="width: 579px; height: 14px; text-align: left">
                    <asp:DropDownList ID="ddlAccessories" runat="server" Font-Size="9pt" Width="533px">
                    </asp:DropDownList>
                    <asp:Button ID="btnDelete" runat="server" Enabled="False" Font-Size="9pt" Text="删除" Width="40px" /></td>
            </tr>
            <tr style="font-size: 12pt">
                <td style="width: 755px; text-align: center">
                </td>
                <td style="width: 755px; height: 35px; text-align: center">
                    <asp:Button ID="btnSend" runat="server" Font-Size="9pt" OnClick="btnSend_Click" Text="发送"
                        Width="77px" /></td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值