Solved

classic asp : send html email

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 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 position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

791 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