Consulting

Results 1 to 15 of 15

Thread: Changing SMTP server automatically

  1. #1
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location

    Changing SMTP server automatically

    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.

    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, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    I'm turning this into my own blog!

    Found this article 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
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by firefytr
    Blog on!


    (Anne will call me a dork as soon as she sees this! )
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Ken,

    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?cod...okaccounts.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!)

    Good luck on this great experiment!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!

    I'll keep working on it, and let you all know what I come up with.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Ken,

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

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

    Happy coding...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #9
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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.

    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!

    Before/After Pictures:
    Last edited by Aussiebear; 04-11-2023 at 05:54 AM. Reason: Adjusted the code tags
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  10. #10
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Ken,

    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...

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

    Later...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!

    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.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Ken,

    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...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  13. #13
    VBAX Regular
    Joined
    Jun 2005
    Posts
    8
    Location
    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.

  14. #14
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi, and welcome to VBAX!

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

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

    Thanks,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  15. #15
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by kpuls
    I always like to make things infinitely more difficult than they need to be?
    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. (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!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •