PDA

View Full Version : Changing SMTP server automatically



Ken Puls
04-17-2005, 10:44 PM
Hey guys,

I have an interesting issue here. I have a laptop, and would like to use it at home, at work, and on the road. The issue I've got, though, is the way my ISP deals with SMTP for outgoing email.

I have a DSL connection at home with an ISP called Telus (Canada). They insist that all outbound email must go through them. If I set up my outbound SMTP server as anything other than smtp.telus.net, I cannot send email. Further, in order to use my DSL connection, I must register my MAC address with Telus.

This is all good, until I leave home. If I plug my laptop in at work, where we use a different ISP, I cannot send email. No doubt because the MAC address of their firewall is different, so it won't let me authenticate to Telus's SMTP server. I can also see how this will be an issue if I hit a "hot spot" with Wireless access as well.

Does anyone know how to deal with this? The only thing I can think of is to use VBA to test the name of the ISP (that could be fun), and change the SMTP via code depending on if it is/isn't Telus.

I don't suppose that I am overthinking this, am I? I'm really hoping that there is an easier solution. : pray2:

I am going to email my ISP to find out if there is a setting on their end, but having dealt with this company before, I'm not exactly hopeful...

Ken Puls
04-21-2005, 03:20 PM
Okay, guys. My ISP has responded to me to tell me, essentially, that this isnt their problem. Really helpful, these guys are. :(

Can someone help me with this a bit. I need a routine to change the SMTP server for a outlook email account.

Thanks!

Ken Puls
04-21-2005, 11:02 PM
I'm turning this into my own blog! :)

Found this article (http://groups-beta.google.com/group/microsoft.public.office.developer.outlook.vba/browse_thread/thread/e58c58b6b62bd06/f08c45be4ea20c12?q=R4z4d.57072$zT6.47313@bignews5.bellsouth.net&rnum=2#f08c45be4ea20c12) which looks like it will do exactly what I need. I'll try and give it a shot over the next couple of days.

Gotta say, though, I love this line in the post:


Note as always, if this code destroys your registry, I never heard of you
and don't know you

LOL

Zack Barresse
04-21-2005, 11:07 PM
Blog on!

Ken Puls
04-22-2005, 07:37 AM
Blog on!

:super:

(Anne will call me a dork as soon as she sees this! :rotlaugh:)

MOS MASTER
04-28-2005, 02:23 PM
Hi Ken, :D

I've never tried to change the SMTP server so I wouldn't know where to begin.

But perpaps retrieving the information first helps you on you're way:
http://vbnet.mvps.org/index.html?code/reg/regoutlookaccounts.htm

Major caveat is always the restarting bit off the application to get this done..

Haven't tested it myself but when programming with CDO mail you always have to provide you're SMTP-server and port and stuff...Perhaps there's an angle for you to jump in...

If you just put another SMTP-server and port in the code than you could have a sollution...(Really don't know if this works...just a thought!) :rofl:

Good luck on this great experiment! :whistle:

Ken Puls
04-29-2005, 01:22 PM
Thanks, Joost!

It's more information to play with there. I've had a go with the reference I posted above, but to date have managed something strange...

I can create a new SMTP key in the registry, but it doesn't modify the old one. It creates a new key so that there are two in the same folder. (key/hive/whatever)

I've had little experience playing with Binary, which is required for the SMTP value, but found that part very strange...

All I can say at this point is that system restore is my friend! :yes

I'll keep working on it, and let you all know what I come up with. :thumb

MOS MASTER
04-29-2005, 01:28 PM
Hi Ken, :D

You're welcome...does seam like an interesting challenge!

If I stumble on more usefull code, I'll be shure to post it! :whistle:

Happy coding...

Ken Puls
05-18-2005, 10:18 PM
Okay guys, an update here.

Still no joy, but this is what I have. It's all been adapted from the link I posted above, and I haven't delved into the one you gave me yet, Joost. Need to get there, but have been working on other projects. :yes

At any rate, the intent of the following code was to change the key holding my VBAX mail account to the mail.vbaexpress.com SMTP server automatically.


Const HKEY_CURRENT_USER = &H80000001
Const WMICONST = "winmgmts:{impersonationlevel=impersonate}!root\default:"
Const sMainRegKey = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\" & _
"Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\"

Private Sub WriteSMTP_VBAX()
Dim nRet, objRegistry As Object
Set objRegistry = GetObject(WMICONST & "StdRegProv")
'Change SMTP server to mail.vbaexpress.com
nRet = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, sMainRegKey & "00000003", "SMTP Server ", _
Array( _
Asc("m"), 0, Asc("a"), 0, Asc("i"), 0, Asc("l"), 0, _
Asc("."), 0, _
Asc("v"), 0, Asc("b"), 0, Asc("a"), 0, _
Asc("e"), 0, Asc("x"), 0, Asc("p"), 0, Asc("r"), 0, Asc("e"), 0, Asc("s"), 0, Asc("s"), 0, _
Asc("."), 0, _
Asc("c"), 0, Asc("o"), 0, Asc("m"), 0, 0, 0))
End Sub

The code above accesses the correct hive, but it creates a new key in the folder. Strangely, even if an SMTP key already exists, it will create another one without writing over the existing. (Picture attached.) I've been running this from Excel and opening Outlook afterwards, but no luck in getting it to take.

Even stranger, if I nuke the exisitng key (so there are no SMTP keys), then I run the code, it will create a new key with the vbaexpress.com info (in binary) as it should. Start Outlook though, and the SMTP for that account is blank, despite the key existing.

I was wondering if it would work by running it from a vbs script, but wouldn't know where to begin on converting it. If anyone could whip that off quick, I'd love to give it a test, but if not... well... I guess I'll keep on fighting! :banghead:

Before/After Pictures:

MOS MASTER
05-19-2005, 11:39 AM
Hi Ken, :yes

Yeah it does seam a strugle to accomplish this!

I would love to help you out on this one but testing your code while editing my registry is one bridge to far for me...:devil:

If there's more time I'll do some more research for you. Maybe there's something more to be discoverd.

Later...:whistle:

Ken Puls
05-20-2005, 08:20 AM
Hey Joost!

Just FYI... if you are feeling brave...

Set a System Restore point, then run the code. You can actually just delete the second key created, but if you do succeed in overwriting, you could also restore from the system restore point.

I'm not expecting you to do that, just giving you the path if you felt both brave and crazy! :giggle

I read a bit at the link you posted for me as well. It's more set for reading the values, rather than writing though. Something there about opening the key though... need to research more.

MOS MASTER
05-20-2005, 11:01 AM
Hi Ken, :yes

Well I do feel I'm kinda brave..but like I've said before I draw the line there. (For answering a question I will never test on the registry)

I'm familiar with the system restore thingie..do I like exporting and importing the registry back more..(for me that's faster)

But like I said Ill try and do some more research for you...:p

avkb03
06-02-2005, 08:03 AM
Why don't you just create 2 different Outlook profiles that point to the same data file? Then you choose which profile to use when loading Outlook (Home, Work). Each profile can use it's own POP/SMTP settings.

Start -> Control Panel -> Mail
Show Profiles
Add

Then find the location of your current Outlook PST file.

Ken Puls
06-02-2005, 08:33 AM
Hi, and welcome to VBAX!

I always like to make things infinitely more difficult than they need to be? :dunno

Seriously, I didn't know you could. I'll look in to that!

Thanks,

MOS MASTER
06-07-2005, 09:56 AM
I always like to make things infinitely more difficult than they need to be? :dunno
Yess avkb...Welcome to VBAX!

Couldn't agree with you more Ken...to get more shamefull...I have my Outlook set-up this way because I always travel allot. :banghead: (The first thing I do when I start Outlook is choose the right profile from the list)

I'm also one of those people who totally forgets about the user interface when we can fix it whit code....

Thank you for the Wake-up call from me aswell! :whistle: