前台页面 SendEmailaspx 代码
<h>
发送电子邮件演示
</h>
<table cellpadding= cellspacing= border= >
<tr>
<td class=style>
邮箱地址
</td>
<td class=style>
<asp:TextBox ID=tb_Email runat=server Width=px></asp:TextBox>
</td>
</tr>
<tr>
<td class=style>
抄送至
</td>
<td class=style>
<asp:TextBox ID=tb_cc runat=server Width=px></asp:TextBox>
</td>
</tr>
<tr>
<td class=style>
邮件主题
</td>
<td class=style>
<asp:TextBox ID=tb_Subject runat=server Width=px></asp:TextBox>
</td>
</tr>
<tr>
<td class=style>
邮件内容
</td>
<td class=style>
<asp:TextBox ID=tb_Body runat=server Height=px TextMode=MultiLine Width=px></asp:TextBox>
</td>
</tr>
<tr>
<td class=style>
添加附件
</td>
<td class=style>
<asp:FileUpload ID=tb_Attachment runat=server Width=px />
</td>
</tr>
<tr>
<td align=right colspan=>
<asp:Button ID=btn_SendEmail runat=server Text=发送邮件 OnClick=btn_SendEmail_Click />
</td>
</tr>
</table>
? 后台SendEmailaspxcs代码
protected void btn_SendEmail_Click(object sender EventArgs e)
{
//声明一个Mail对象
MailMessage mymail = new MailMessage()
//发件人地址
//如是自己在此输入自己的邮箱
mymailFrom = new MailAddress()
//收件人地址
mymailToAdd(new MailAddress(tb_EmailText))
//邮件主题
mymailSubject = tb_SubjectText;
//邮件标题编码
mymailSubjectEncoding = SystemTextEncodingUTF;
//发送邮件的内容
mymailBody = tb_BodyText;
//邮件内容编码
mymailBodyEncoding = SystemTextEncodingUTF;
//添加附件
Attachment myfiles = new Attachment(tb_AttachmentPostedFileFileName)
mymailAttachmentsAdd(myfiles)
//抄送到其他邮箱
mymailCCAdd(new MailAddress(tb_ccText))
//是否是HTML邮件
mymailIsBodyHtml = true;
//邮件优先级
mymailPriority = MailPriorityHigh;
//创建一个邮件服务器类
SmtpClient myclient = new SmtpClient()
myclientHost = ;
//SMTP服务端口
myclientPort = ;
//验证登录
myclientCredentials = new NetworkCredential(@@@@@@ *****)//@输入有效的邮件名 *输入有效的密码
myclientSend(mymail)
}
? 效果如下
如下图填入各项点击发送邮件
邮箱内
QQ邮箱内