Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Send HTML Email via CDO

Total Hit ( 4162)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Ever wonder how to send email that looks like a web page? Here is how you do it. Note: You must have CDO for NT referenced for this to work.

Click here to copy the following block
'Sends an email to the appropriate person(s).
'
'From = Email address being sent from
'SendTo = List of email addresses separated by a semicolon. Example:
'    sm@xyz.com; steve@work.com; jane@home.com
'Subject = Text that summarizes what the email is about
'HTMLText = Body of text that is the email
'AttachmentPath = Directory in which the attachment resides
'Attachment = File to send with the email

Sub SendEmailHTML(From As String, SendTo As String, Subject As String, _
  HTMLText As String, Optional AttachmentPath As String, _
  Optional Attachment As String, Optional CC As String)
  Const constRoutine As String = "SendEmailHTML"

  Dim strSendTo As String
  Dim objSendMail As CDONTS.NewMail
  Dim i As Integer

  On Error GoTo ErrorHandler
  'Do not cause the user a major error, just log the error and keep going
  
  If SendTo = "" Then Exit Sub

  Set objSendMail = New CDONTS.NewMail

  With objSendMail
    On Error Resume Next
    .From = From
    If CC <> "" Then
      .CC = CC
    End If

    On Error GoTo ErrorHandler
    .To = SendTo
    .Subject = Subject
    .Body = HTMLText
    .MailFormat = CdoMailFormats.CdoMailFormatMime
    .BodyFormat = CdoBodyFormats.CdoBodyFormatHTML
  
    AttachmentPath = Trim$(AttachmentPath)
    If AttachmentPath <> "" Then
      If Right$(AttachmentPath, 1) <> "\" Then
        AttachmentPath = AttachmentPath & "\"
      End If
      .AttachFile (AttachmentPath & Attachment)
    End If
    .Send
  End With
  
ExitMe:
  Set objSendMail = Nothing
  Exit Sub

ErrorHandler:
  'Send error back
  Err.Raise Err.Number, Err.Source, Err.Description

End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.