'=======================================================================================
'
' Example 8
'
' Send an email with text and HTML alternatives
'
'=======================================================================================
' Create a Chilkat.MailMan object for sending,
' and set the necessary properties and unlock the component.
Dim mailman as New Chilkat.MailMan()
mailman.UnlockComponent(Request.form("unlockCode"))
' Tell the MailMan the SMTP server to be used for sending email.
mailman.SmtpHost = Request.form("smtpServer")
' Optionally provide the SMTP server with a login and password.
' The MailMan will automatically choose the most secure SMTP authorization
' method available.
if Request.form("smtpLogin") <> "" then
mailman.SmtpUsername = Request.form("smtpLogin")
mailman.SmtpPassword = Request.form("smtpPassword")
end if
' Create an Email object. The mailman will send the email.
Dim email As New Chilkat.Email()
' Give our email a subject, recipient, and return address.
email.From = Request.form("fromAddr")
email.AddTo("",Request.form("recipient"))
email.Subject = "Chilkat ASP.NET " + Request.form("exampleSelected")
' Create some HTML
Dim htmlText As String
htmlText = "<html>" + _
"<head>" + _
"<title>Sample HTML Email</title>" + _
"</head>" + _
"<body bgcolor=""#FFFFFF"">" + _
"<h4 align=""center""><img src=""cid:IMAGE_CID""></h4>" + _
"<h4 align=""center""><span><a href=""dotNetEmail.asp""><font face=""Microsoft Sans Serif"">Email.NET</font></a></span></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetZip.asp"">Zip.NET</a> " + _
" </font></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetCrypt.asp"">Crypt.NET</a></font></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetXml.asp"">XML.NET</a></font></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetCharset.asp"">Charset.NET</a></font></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetSmime.asp"">S/MIME.NET</a></font></h4>" + _
"<h4 align=""center""><font face=""Microsoft Sans Serif""><a href=""http://www.chilkatsoft.com/dotNetMht.asp"">MHT.NET</a></font></h4>" + _
"</body>" + _
"</html>"
' Now add the GIF image. This is not added as an attachment, but as related data because it is
' part of the HTML.
' We can use the Crypt object to convert the GIF data from base64 to binary because the base64
' encoding/decoding methods do not require unlock codes.
Dim crypt As New Chilkat.Crypt
Dim imageCid As String
imageCid = email.AddRelatedData("chilkat.gif",crypt.DecodeBase64(gifData))
' Replace IMAGE_CID in the HTML with the imageCid returned.
htmlText = htmlText.Replace("IMAGE_CID",imageCid)
' Now set the HTML body of the email
email.SetHtmlBody(htmlText)
' Now provide a plain-text alternative. Recipients with mail clients that cannot handle
' HTML will see the plain-text.
email.AddPlainTextAlternativeBody("This is the plain-text alternative body")
Response.write("Plain text body: ["+email.GetPlainTextBody+"]<br><br>")
' Connect to the SMTP server and send mail.
if (mailman.SendEmail(email)) then
Response.write("Mail sent!")
else
Response.write("Errors in sending email!")
Response.write(mailman.LastErrorHtml)
end if
|