Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

pros & cons of various techniques for programmatically sending email

Posted on 2011-02-12
4
Medium Priority
?
396 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
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…
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…
Suggested Courses

604 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