This topic is locked

HTML Email Template

10/3/2007 11:12:34 PM
ASPRunnerPro Tips and tricks
M
Michael7 author

HTML email solution
There is a sample layout below of how the email should be formatted. simply add HTML using the below format.

Images can be used but make sure you use the full address and not just /includes/images/

[/i]

Edit : /commonfunctions.asp


Change : myMail.TextBody= message

To : myMail.HTMLBody= message
Edit : /dbcommon.asp

Add Relevant Details to :

  • cFrom
  • cSmtpServer
  • cSmtpPort
  • cSMTPUser
  • cSMTPPassword
    Add to : /includes/_events.asp then change the blue fields and edit HTML as you required

    **


    <%

    Sub AfterEdit()
    '****
    Send HTML email ****

    sqlQuery = "SELECT [color="#0000ff"]* From = "&GetRequestForm("editid1")
    Set sqlRecord = dbConnection.Execute(sqlQuery)

    If Not sqlRecord.EOF Then
    email = ""&sqlRecord("[color="#0000ff"]field name holding email address")&", ")

    subject = "Hello "&sqlRecord("[color="#0000ff"]field1")&" (some more text : "&sqlRecord("")&")"

    message = "<body bgcolor=""#E4E4E4"">&vbCrLf &

    " <table style=""border-collapse: collapse"" cellpadding=""3"" width=""85%"" id=""Main"" align=""center"">" &vbCrLf &


    " <tr>" &vbCrLf &

    " <td bgcolor=""#77AFF1"">some text "&sqlRecord("[color=#0000ff]field")&"</td>" &vbCrLf &


    " </tr>" &vbCrLf &

    " <tr>" &vbCrLf &


    " <td bgcolor=""#FFFFFF"" style=""border-left: 1px outset #000000; border-right: 1px outset #000000;"">some text</td>" &vbCrLf &

    " </tr>" &vbCrLf &


    " <tr>" &vbCrLf &

    " <td bgcolor=""#FFFFFF"" align=""center""style="" border-left: 1px outset #000000; border-right: 1px outset #000000;"">more text</td>" &vbCrLf &


    " </tr>" &vbCrLf &

    " <tr>" &vbCrLf &


    " <td bgcolor=""#4A4A4A"" align=""left"" width=""100%"" style=""border-left: 1px outset #000000"">more text</td>" &vbCrLf &

    " </tr>" &vbCrLf &


    " </table></body>"
    End If

    sqlRecord.Close

    Set sqlRecord= Nothing

    sendmail email, subject, message
    '** Redirect to another page ****

    Response.Redirect "/youremailwassentconfirmation.asp"
    End Sub

    %>


lefty 3/10/2012



HTML email solution
There is a sample layout below of how the email should be formatted. simply add HTML using the below format.

Images can be used but make sure you use the full address and not just /includes/images/

[/i]

Edit : /commonfunctions.asp


Change : myMail.TextBody= message

To : myMail.HTMLBody= message
Edit : /dbcommon.asp

Add Relevant Details to :

  • cFrom
  • cSmtpServer
  • cSmtpPort
  • cSMTPUser
  • cSMTPPassword
    Add to : /includes/_events.asp then change the blue fields and edit HTML as you required

    **


    <%

    Sub AfterEdit()
    '****
    Send HTML email ****

    sqlQuery = "SELECT [color="#0000ff"]* From = "&GetRequestForm("editid1")
    Set sqlRecord = dbConnection.Execute(sqlQuery)

    If Not sqlRecord.EOF Then
    email = ""&sqlRecord("[color="#0000ff"]field name holding email address")&", ")

    subject = "Hello "&sqlRecord("[color="#0000ff"]field1")&" (some more text : "&sqlRecord("")&")"

    message = "<body bgcolor=""#E4E4E4"">&vbCrLf &

    " <table style=""border-collapse: collapse"" cellpadding=""3"" width=""85%"" id=""Main"" align=""center"">" &vbCrLf &


    " <tr>" &vbCrLf &

    " <td bgcolor=""#77AFF1"">some text "&sqlRecord("[color="#0000ff"]field")&"</td>" &vbCrLf &


    " </tr>" &vbCrLf &

    " <tr>" &vbCrLf &


    " <td bgcolor=""#FFFFFF"" style=""border-left: 1px outset #000000; border-right: 1px outset #000000;"">some text</td>" &vbCrLf &

    " </tr>" &vbCrLf &


    " <tr>" &vbCrLf &

    " <td bgcolor=""#FFFFFF"" align=""center""style="" border-left: 1px outset #000000; border-right: 1px outset #000000;"">more text</td>" &vbCrLf &


    " </tr>" &vbCrLf &

    " <tr>" &vbCrLf &


    " <td bgcolor=""#4A4A4A"" align=""left"" width=""100%"" style=""border-left: 1px outset #000000"">more text</td>" &vbCrLf &

    " </tr>" &vbCrLf &


    " </table></body>"
    End If

    sqlRecord.Close

    Set sqlRecord= Nothing

    sendmail email, subject, message
    '** Redirect to another page ****

    Response.Redirect "/youremailwassentconfirmation.asp"
    End Sub

    %>




Anyone hae a better way of doing this Tried Find and replace but it is very tedious I have 1000 lines of html? ANy Ideas

" "" quotes are tedious as well as &vbCrLf &
If you could wrie a macro or before process event to update "" and & vbCrLf &
for begining and end of sentance it will save all us html event template writers thousands of hours of work . I wiould pay for this as it takes hours and hours to accomplish.

admin 3/10/2012

Check this article:

http://www.asprunner.com/forums/topic/19089-sending-templated-email-messages/
Though this is for PHP the idea is very simple.

  1. Prepare email template
  2. Load it from file in your event
  3. Replace placeholders in email template with the actual values
  4. Send email as usual