Simple Classic ASP Send Email Subroutine

Discussion in 'ASP Snips' started by AltonConsulting, Feb 20, 2007.

  1. '============================================================================
    ' 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)
  2. I have noticed a lot of views on this post, but disappointingly no one has commented (given feedback) or even more important, contributed any other code blocks, tips, or advice on "classic" ASP. I would like to see this forum grow and become a great resource for classic ASP developers and future ASP developers.

    I know there is a big buzz around the whole ASP.NET realm, but unless creating large, application oriented internet projects, classic ASP is perfect for accomplishing whatever needed on most sites (other than heavy application based "Dot-Com" sites), and makes a web developer's life much easier.

    I am also going to go as far as to say ASP is far superior to PHP (which in my opinion is a pain in the a$$).

    Tell me what you think...
  3. KCWebMonkey

    KCWebMonkey Perch

    i'll bet the high view count is because people are coming in from Google and viewing the post... probably copying it and leaving.
  4. Stephen

    Stephen US Operations Staff Member

    yes, its highly 'googled' around here!
  5. BluJag

    BluJag Perch

    I agree asp v php, but probably because I'm not very familiar with php. As to .net, I think it's the only way to go, forget classic asp. MS have made it very easy (with Web Developer Express as a free download) and JoDo host .net 2 along with Ajax.net, so what more could you want ? Why bother with classic asp and it's associated spaghetti code and lack of proper types etc?
  6. KenPalmer

    KenPalmer Guppy

    Thanks Dan. You saved my bacon! Your code worked like a champ virtually unedited.

Share This Page

JodoHost - 26,000 hosting end-users in 100 countries
Plesk Web Hosting
VPS Hosting
H-Sphere Web Hosting
Other Services