Solved

classic asp : send html email

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bootstrap footer centering and columns alignement 3 59
hosting images 4 30
AdminLTE with wordpress 15 64
Save ms data to server side. 19 46
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

810 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