Solved

pros & cons of various techniques for programmatically sending email

Posted on 2011-02-12
4
386 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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

688 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