Solved

SMTP redundancies: How do I build them into my apps?

Posted on 2008-06-23
4
289 Views
Last Modified: 2013-11-30
SMTP mail services are a very important part of our web applications.  We run ASP.NET C# and Classic ASP apps.

I would like to know several ways to make these services redundant such that if one server goes down the other servers will still send content.

I have configured DNS, DCs, and AD on our systems, and I speculate that perhaps an abstract name can be used for SMTP services provided by multiple servers. If this is the case, how can I set it up using the MSFT DNS console?

Is there a way to do this in programming, both in Classic ASP VBScript, and in C#/.NET? In programming, there would need to be some test of SMTP connectivity followed by the attempt to send. Can someone post or link to a code sample?

Any other methods of accomplishing the same work?

Thank you,
-KF
0
Comment
Question by:kennethfine
[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
  • 2
4 Comments
 
LVL 1

Expert Comment

by:mastertechnc
ID: 21851447
The easiest thing is to setup redundancy in your code to connect to backup smtp servers.
0
 
LVL 6

Author Comment

by:kennethfine
ID: 21851471
Thanks. Can you tell me how to do that?  
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 21866416
Hi,

I guess a rather simple (but still working) method would be to simply add all your host and the matching credentials into an array or object and simply loop through and exit on first successful transmission?!? Review the attached code snippet for a workable lightweight solution (tried it quickly on my dev pc. Added two hosts, my home smtp server and one in my office. Then ran the web app, first on home network then i connected using vpn mid through and it worked. It keeps looping if unsuccessful and breaks the loop when successful. You should be able to add any number hosts.)

The code snippet is in VB, I'm not a C# guy but I hope You get the general idea. You will need to redimension the hosts Object to match the number of SMTP Hosts you want to use.
'You will need to import System.Net.Mail (using in C#?!?)
Imports System.Net.Mail
'Dimension an Object or array to hold the smtp hosts and credentials
Private hosts(1, 2) As Object
 
        'Populate the SMTP Hosts and credentials
        hosts(0, 0) = "SMTP-Host-1"
        hosts(0, 1) = "User-Host-1"
        hosts(0, 2) = "Pass-Host-1"
        hosts(1, 0) = "SMTP-Host-2"
        hosts(1, 1) = "User-Host-2"
        hosts(1, 2) = "Pass-Host-2"
        'The logic to build message, instantiate smtp client and loop through hosts
        Dim m As New MailMessage()
        m.From = New MailAddress("sender@yourdomain.com") 'From Your business logic
        m.To.Add("recipient@somedomain.com") 'From Your business logic
        m.Subject = "The Subject Of Your Email" 'From Your business logic
        m.Body = "The Content Of Your Email" 'From Your business logic
        m.IsBodyHtml = True
        m.Priority = MailPriority.High
        Dim c As New SmtpClient()
        c.Timeout = 1000 'Timeout of Your choice depending on Your infrastructure
        Dim i As Integer = 0
        Do While i <= UBound(hosts)
            c.Host = hosts(i, 0).ToString
            Dim creds As New System.Net.NetworkCredential(hosts(i, 1).ToString, hosts(i, 2).ToString)
            c.Credentials = creds
            Try
                c.Send(m)
                'The transmission was successful, exit the loop through hosts.
                Exit Do
            Catch ex As Exception
                'The transmission was not successful, exit try and continue to loop through hosts.
                Exit Try
            End Try
            i += 1
        Loop
        m.Dispose()

Open in new window

0
 
LVL 6

Author Comment

by:kennethfine
ID: 21868056
Thanks, good solution. I appreciate the help!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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