Solved

classic asp : send html email

Posted on 2012-03-22
5
1,064 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now