'(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 |
![]() |