Sending E-Mail. Microsoft SMTP Service Simple Mail Transport Protocol Does not support the Post...

Post on 13-Dec-2015

212 views 0 download

Transcript of Sending E-Mail. Microsoft SMTP Service Simple Mail Transport Protocol Does not support the Post...

Sending E-MailSending E-Mail

Microsoft SMTP ServiceMicrosoft SMTP Service

Simple Mail Transport Protocol

Does not support the Post Office Protocol (POP)

InetPub\MailRoot\Pickup

InetPub\MailRoot\Drop

Send e-mail

receive e-mail

Sending a Simple E-Mail Sending a Simple E-Mail MessageMessage

<%@ Import Namespace="System.Web.Mail" %>

<Script runat="Server">Sub Button_Click( s As Object, e As EventArgs ) SmtpMail.Send( _ mailfrom.Text, _ mailto.Text, _ mailsubject.Text, _ mailbody.Text )End Sub</Script>

Sending a Simple E-Mail Sending a Simple E-Mail MessageMessage

<html><head><title>SendMail.aspx</title></head><body>

<h1>Send Mail:</h1><form runat="Server">

<b>From:</b><br><asp:TextBox ID="mailfrom" Columns="50" Runat="Server" /><p><b>To:</b><br><asp:TextBox ID="mailto" Columns="50" Runat="Server" /><p>

<b>Subject:</b><br><asp:TextBox ID="mailsubject" Columns="50" Runat="Server" /><p><b>Body:</b><br><asp:TextBox ID="mailbody" TextMode="Multiline" Columns="50" Rows="10" Runat="Server" /><p><asp:Button Text="Send!" OnClick="Button_Click" Runat="Server" /></form></body></html>

Adding AttachmentsAdding Attachments<%@ Import Namespace="System.Web.Mail" %><%Dim objMailMessage As MailMessageDim objMailAttachment As MailAttachment

' Create the Mail AttachmentobjMailAttachment = New MailAttachment( "c:\BizPlan.doc" )

' Create the Mail MessageobjMailMessage = New MailMessageobjMailMessage.From = "you@somewhere.com"objMailMessage.To = "joe@somewhere.com"objMailMessage.Subject = "Secret Business Plan"objMailMessage.Body = "Here's the plan (don't show it to anyone!)"objMailMessage.Attachments.Add( objMailAttachment )

' Send the Mail MessageSmtpMail.Send( objMailMessage )%>

BizPlan Sent!

Sending HTML E-MailSending HTML E-Mail<%@ Import Namespace="System.Web.Mail" %><%Dim objMailMessage As MailMessageDim strHTMLBody As String' Create the HTML Message BodystrHTMLBody = "<html><head>" & _ "<title>Thank You!</title>" & _ "</head><body bgcolor=lightblue>" & _ "<font face=Script size=6>" & _ "Thank you for registering!" & _ "</font></body></html>"' Create the Mail MessageobjMailMessage = New MailMessageobjMailMessage.From = "you@somewhere.com"objMailMessage.To = "joe@somewhere.com"objMailMessage.Subject = "Thanks for Registering!"objMailMessage.Body = strHTMLBodyobjMailMessage.BodyFormat = MailFormat.HTML' Send the Mail MessageSmtpMail.Send( objMailMessage )%>HTML Email Sent!