'(1)创建MailMessage实例 Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress) '(2)赋值MailMessage的属性 mm.Subject = "HTML-Formatted Email Demo Using the IsBodyHtml Property" mm.Body = "<h2>This is an HTML-Formatted Email Send Using the <code>IsBodyHtml</code> Property</h2><p>Isn't HTML <em>neat</em>?</p><p>You can make all sorts of <span style=""color:red;font-weight:bold;"">pretty colors!!</span>.</p>" mm.IsBodyHtml = True '(3) 创建SmtpClient对象 Dim smtp As New SmtpClient '(4)发送MailMessage (将使用Web.config设置) smtp.Send(mm) |
x-sender: ToEmailAddress x-receiver: FromEmailAddress mime-version: 1.0 from: FromEmailAddress to: ToEmailAddress date: 25 Jul 2006 15:06:44 -0700 subject: HTML-Formatted Email Demo Using the IsBodyHtml Property content-type: text/html; charset=us-ascii content-transfer-encoding: quoted-printable <h2>This is an HTML-Formatted Email Send Using the <code>IsBodyHtml</code>= Property</h2><p>Isn't HTML <em>neat</em>?</p><p>You can make all sorts= of <span style=3D"color:red;font-weight:bold;">pretty colors!!</span>.</p> |
<table border="0"> <tr> <td><b>Your Email:</b></td> <td><asp:TextBox runat="server" ID="UsersEmail" Columns="30"></asp:TextBox></td> </tr> <tr> <td><b>File to Send:</b></td> <td> <asp:FileUpload ID="AttachmentFile" runat="server" /> </td> </tr> <tr> <td colspan="2"> <b>Body:</b><br /> <asp:TextBox runat="server" ID="Body" TextMode="MultiLine" Columns="55" Rows="10"></asp:TextBox> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Button runat="server" ID="SendEmail" Text="Send Feedback" /> </td> </tr> </table> |
'确保已经上传一个文件 If String.IsNullOrEmpty(AttachmentFile.FileName) OrElse AttachmentFile.PostedFile Is Nothing Then Throw New ApplicationException("Egad, a file wasn't uploaded... you should probably use more graceful error handling than this, though...") End If '(1) 创建MailMessage实例 Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress) '(2)赋值MailMessage的属性 mm.Subject = "Emailing an Uploaded File as an Attachment Demo" mm.Body = Body.Text mm.IsBodyHtml = False '附加文件 mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName)) '(3) 创建SmtpClient对象 Dim smtp As New SmtpClient '(4)发送MailMessage (将使用Web.config设置) smtp.Send(mm) |
Try '(1)创建MailMessage实例 Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress) '(2)赋值MailMessage的属性 mm.Subject = "Test Email... DO NOT PANIC!!!1!!!111!!" mm.Body = "This is a test message..." mm.IsBodyHtml = False '(3)创建SmtpClient对象 Dim smtp As New SmtpClient 'SMTP设置... smtp.Host = Hostname.Text If Not String.IsNullOrEmpty(Port.Text) Then smtp.Port = Convert.ToInt32(Port.Text) End If If Not String.IsNullOrEmpty(Username.Text) Then smtp.Credentials = New NetworkCredential(Username.Text, Password.Text) End If '(4)发送MailMessage(将使用Web.config设置) smtp.Send(mm) '显示一个客户端弹出窗口,解释该该邮件已经发出 ClientScript.RegisterStartupScript(Me.GetType(), "HiMom!", String.Format("alert('An test email has successfully been sent to {0}');", ToAddress.Replace("'", "\'")), True) Catch smtpEx As SmtpException '当发送电子邮件消息时发生了一个问题 ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True) Catch generalEx As Exception '发生另外的一些问题 ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True) End Try |
自由广告区 |
分类导航 |
邮件新闻资讯: IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮 电子邮箱 | 反垃圾邮件|邮件客户端|网络安全 行业数据 | 邮件人物 | 网站公告 | 行业法规 网络技术: 邮件原理 | 网络协议 | 网络管理 | 传输介质 线路接入 | 路由接口 | 邮件存储 | 华为3Com CISCO技术 | 网络与服务器硬件 操作系统: Windows 9X | Linux&Uinx | Windows NT Windows Vista | FreeBSD | 其它操作系统 邮件服务器: 程序与开发 | Exchange | Qmail | Postfix Sendmail | MDaemon | Domino | Foxmail KerioMail | JavaMail | Winwebmail |James Merak&VisNetic | CMailServer | WinMail 金笛邮件系统 | 其它 | 反垃圾邮件: 综述| 客户端反垃圾邮件|服务器端反垃圾邮件 邮件客户端软件: Outlook | Foxmail | DreamMail| KooMail The bat | 雷鸟 | Eudora |Becky! |Pegasus IncrediMail |其它 电子邮箱: 个人邮箱 | 企业邮箱 |Gmail 移动电子邮件:服务器 | 客户端 | 技术前沿 邮件网络安全: 软件漏洞 | 安全知识 | 病毒公告 |防火墙 攻防技术 | 病毒查杀| ISA | 数字签名 邮件营销: Email营销 | 网络营销 | 营销技巧 |营销案例 邮件人才:招聘 | 职场 | 培训 | 指南 | 职场 解决方案: 邮件系统|反垃圾邮件 |安全 |移动电邮 |招标 产品评测: 邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端 |