zoukankan      html  css  js  c++  java
  • asp.net webform 发送电子邮件

    <div>
    <h2>
    发送电子邮件演示
    </h2>
    <table cellpadding="0" cellspacing="0" border="0" style="font-family: 宋体, Arial, Helvetica, sans-serif;
    font-size: 15px; 411px;">
    <tr>
    <td class="style5">
    邮箱地址:
    </td>
    <td class="style6">
    <asp:TextBox ID="tb_Email" runat="server" Width="269px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="style5">
    抄送至:
    </td>
    <td class="style6">
    <asp:TextBox ID="tb_cc" runat="server" Width="268px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="style5">
    邮件主题:
    </td>
    <td class="style6">
    <asp:TextBox ID="tb_Subject" runat="server" Width="268px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="style5">
    邮件内容:
    </td>
    <td class="style6">
    <asp:TextBox ID="tb_Body" runat="server" Height="63px" TextMode="MultiLine" Width="266px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td class="style5">
    添加附件:
    </td>
    <td class="style6">
    <asp:FileUpload ID="tb_Attachment" runat="server" Width="265px" />
    </td>
    </tr>
    <tr>
    <td align="right" colspan="2">
    <asp:Button ID="btn_SendEmail" runat="server" Text="发送邮件"
    onclick="btn_SendEmail_Click"/>
    </td>
    </tr>
    </table>
    </div>

    后端代码:

    protected void btn_SendEmail_Click(object sender, EventArgs e)
    {
    //声明一个Mail对象
    MailMessage mymail = new MailMessage();
    //发件人地址
    //如是自己,在此输入自己的邮箱
    mymail.From = new MailAddress("15826604192@163.com");
    //收件人地址
    mymail.To.Add(new MailAddress(tb_Email.Text));
    //邮件主题
    mymail.Subject = tb_Subject.Text;
    //邮件标题编码
    mymail.SubjectEncoding = System.Text.Encoding.UTF8;
    //发送邮件的内容
    mymail.Body = tb_Body.Text;
    //邮件内容编码
    mymail.BodyEncoding = System.Text.Encoding.UTF8;
    //添加附件
    Attachment myfiles = new Attachment(tb_Attachment.PostedFile.FileName);
    mymail.Attachments.Add(myfiles);
    //抄送到其他邮箱
    mymail.CC.Add(new MailAddress(tb_cc.Text));
    //是否是HTML邮件
    mymail.IsBodyHtml = true;
    //邮件优先级
    mymail.Priority = MailPriority.High;
    //创建一个邮件服务器类
    SmtpClient myclient = new SmtpClient();
    myclient.Host = "SMTP.163.com";
    //SMTP服务端口
    myclient.Port = 25;
    //验证登录
    myclient.Credentials = new NetworkCredential("@@@@@@", "*****");//"@"输入有效的邮件名, "*"输入有效的密码
    myclient.Send(mymail);
    }

  • 相关阅读:
    EF中的EntityState几个状态的说明
    sql server 更新表,每天的数据分固定批次设置批次号sql
    bootstrap Validators
    马老师 生产环境mysql主从复制、架构优化方案
    PHP在微博优化中的“大显身手”
    将form表单转化为json数据
    免费资源库收集
    奇怪的php问题
    PHP 大数自动转换为科学计数法
    access database in a helper function ?
  • 原文地址:https://www.cnblogs.com/hbh123/p/5135541.html
Copyright © 2011-2022 走看看