Solved

pros & cons of various techniques for programmatically sending email

Posted on 2011-02-12
4
375 Views
Last Modified: 2012-06-27
Over the years I've written several VB6 programs that send emails to people, usually run by a Scheduled Task. The programs read data from a SQL database, then send emails based on what's returned by a SQL Query and usually update the database to the effect that the email was sent.

I've used CDO messaging, Outlook VBA automation and possibly some other technique(s). I know CDO is being retired. Outlook VBA I find easy to use but once in a while Outlook on the server gets corrupted and emails stop being sent until I log on to the server, start Outlook in safe mode, close Outlook, etc. So that can be a bit of a maintenance problem.

Over the past two months or so, one of my CDO based programs has started duplicating messages sent to users. For example, Friday 25 emails were sent out by the program, 3 of them were sent multiple times. One of the 3 was sent 15 times. I've put a 60 second sleep statement in the program, so I can see the message wasn't sent repeatedly by my program -- all the messages have one minute intervals on their Sent date/time stamp. But the ones the were duplicated show as having been sent multiple times AT THE SAME TIME. So something's gotten fouled up with sending a message via CDO that causes it to be sent multiple times.

I've rebooted the server a couple of times, the problem persists. I've tried sending the same email repeatedly as a test, about once every 10-20 times it duplicates itself. So there's really something funny going on.

I'm thinking that rather than try to debug an old CDO related problem, I should switch the email delivery technique to something more modern.

What would anyone recommend as a best programming technique for this environment?
0
Comment
Question by:GordonPrince
4 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 300 total points
Comment Utility
We use the .NET mail object. We use task scheduler to run the executables and have never had any problems. It's just about as easy as VBA.
Here's a sample basic program.
Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Mail

Module Module1
    '
    Sub main()
        '
        Dim email As New MailMessage
        Dim SMTP As New SmtpClient
        '
        Try
            '
            ' clear .to and .attachments to avoid another major spam embarrassment
            '
            email.From = New MailAddress("autoSender@domain.com")
            email.To.Add(New MailAddress("bob@domain.com"))
            email.ReplyTo = New MailAddress("Administrator@domain.com")
            email.Subject = "Subject"
            email.Body = "Body"
            email.Attachments.Add(New Attachment("C:\temp\file.txt"))
            '
            SMTP.Host = "SMTP.emailserver.com"
            SMTP.UseDefaultCredentials = False
            SMTP.Credentials = New NetworkCredential("autoSender@domain.com", "password")
            SMTP.Port = 25
            SMTP.Send(email)
            '
            ' 
        Catch ex As Exception
            '
            'Handle failure message
            ' 
        End Try

        ''
    End Sub
    '
End Module

Open in new window

0
 
LVL 3

Assisted Solution

by:rafunk
rafunk earned 100 total points
Comment Utility
If still dealing with VB6, have you tried vbSendMail?
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 100 total points
Comment Utility
Hi, GordonPrince.

I've used both vbSendMail (as rafunk suggested) and OstroSoft's SMTP component to send mail from VB6 and VBScript.  Both are free (OstroSoft doesn't charge for non-commercial development) and both work well.
0
 
LVL 4

Author Comment

by:GordonPrince
Comment Utility
The VB6 is so old, it was time to upgrade. So I upgraded to VB 2008.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now