Automatically Select Smtp Server

TimTDP

Registered User.
Local time
Today, 16:41
Joined
Oct 24, 2008
Messages
213
I use CDO to send e-mails
At work I need to use one smtp server, at home another. Frustrating!

How can I automatically determine which smtp server my computer is connected to, and then use this server when sending e-mail?
 
Using the VBA.Environ() function you can get the value of the operating system's "ComputerName" environment variable. Using that info you can choose an smtp server. Code might look like ...
Code:
Dim smpt as string
Select Case Environ("ComputerName")
  Case "HomeComputer"
    smtp = "myhomeisp.mail.smtp"
  Case "WorkComputer"
    smtp = "myworkisp.smtp"
End Select
...or if you stored that data in a table...
Code:
dim smtp as string
smtp = DLookup("ServerName", "tMyServers", "ComputerName = '" & Environ("ComputerName") & "'")
Cheers,
 

Users who are viewing this thread

Back
Top Bottom