• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1317
  • Last Modified:

classic asp : send html email

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
Aanvik
Asked:
Aanvik
  • 3
  • 2
1 Solution
 
samic400Commented:
'================================================= ===========================
' 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
 
AanvikAuthor Commented:
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
 
samic400Commented:
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
 
AanvikAuthor Commented:
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
 
samic400Commented:
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

Independent Software Vendors: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now