Solved

pros & cons of various techniques for programmatically sending email

Posted on 2011-02-12
4
379 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
ID: 34879744
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
ID: 34883216
If still dealing with VB6, have you tried vbSendMail?
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 100 total points
ID: 34895486
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
ID: 34906476
The VB6 is so old, it was time to upgrade. So I upgraded to VB 2008.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
In this video we show how to create an email address policy 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 Mail Flow…
how to add IIS SMTP to handle application/Scanner relays into office 365.

820 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