Send HTML Email via CDO

Send HTML Email via CDO

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.

'Sends an email to the appropriate person(s).''From = Email address being sent from'SendTo = List of email addresses separated by a semicolon.  Example:'       [email protected]; [email protected]; [email protected]'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 emailSub 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 SubErrorHandler:    'Send error back    Err.Raise Err.Number, Err.Source, Err.DescriptionEnd Sub


This tip has been brought to you by Pragmatic Software Co. Inc, the creators of Defect Tracker, the tool of choice for tracking functional specifications, test cases and software bugs. Learn more at http://www.DefectTracker.com. Affiliate program also available at http://www.PragmaticSW.com/AffiliateSignup.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes