?
Solved

pros & cons of various techniques for programmatically sending email

Posted on 2011-02-12
4
Medium Priority
?
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 1200 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 400 total points
ID: 34883216
If still dealing with VB6, have you tried vbSendMail?
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 400 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This video discusses moving either the default database or any database to a new volume.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 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