Solved

classic asp : send html email

Posted on 2012-03-22
5
1,148 Views
Last Modified: 2012-08-13
Hello Experts.
I am looking for a very simple example to send a html email via classic asp page. I have this register user page, where once registered I would like to send a welcome mail to user. I already have the email template created with the images/css etc... I just need to update few fields there like their name and few links and send the email.

Please help.
0
Comment
Question by:Aanvik
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:samic400
ID: 37753686
'================================================= ===========================
' sendEmail Subroutine by Dan Robertson (danrobertson@ninemanagement.com)
'================================================= ===========================
Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = mailMessage

MyMail.Send
Set MyMail = nothing
End Sub

Dim mailFrom, mailTo, mailSubject, mailMessage

mailFrom = "you@domain.com"
mailTo = "recipient@theirdomain.com"
mailSubject = "This is my subject"
mailMessage = "<html><body>This is my message</body><html>"



Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
0
 
LVL 5

Author Comment

by:Aanvik
ID: 37753702
Thank you for your response... 2 questions here..

How do I use an email template (an html/asp file) here.

mailServer.. how to use it and where?
0
 
LVL 13

Accepted Solution

by:
samic400 earned 500 total points
ID: 37753724
Your web template would be put in here:

mailMessage = "<html><body>Your code here - images, etc.</body><html>"

If your have the smtp piece of IIS already running - you shouldn't have to specify the server. But if you are looking to get something more complex, like defining a mail server and password, you would need something like this:

'================================================= ===========================
' sendEmail Subroutine by Dan Robertson (danrobertson@ninemanagement.com)
'================================================= ===========================
Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = mailMessage
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
MyMail.Configuration.Fields.Update
MyMail.Send
Set MyMail = nothing
End Sub

Dim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword

mailFrom = "you@domain.com"
mailTo = "recipient@theirdomain.com"
mailSubject = "This is my subject"
mailMessage = "<html><body>This is my message</body><html>"
mailServer = "mail.domain.com"
mailUsername = "myUsername"
mailPassword = "myPassword"

Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
0
 
LVL 5

Author Comment

by:Aanvik
ID: 37754053
Thank you... that worked..

I just have one final question... The template file I have is an html large file... Is there any simple way to use it in the above function.. like read file  or something like that?
0
 
LVL 13

Expert Comment

by:samic400
ID: 37754131
What I recommend you do in that case is open the html large file and read it like a text file, line by line, and put it together in a variable. At least that is the way I would go about doing it. Take a peek at the FileSystemObject and how to read a text file, line by line.

Maybe check out www.w3schools.com and somewhere in there you should find something related to filesystemobject.

Good luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question