VB.NET get mail server

S

scorpion53061

Is there a registry setting that I can read in vb.net for windows platforms
that will give me the default mail server for the computer (e.g.
mail.charter.net)
 
C

Cor

Hi Scorpion,
Yes and what was it, if I had known it I had told you so contribute it
please
:)
Cor
 
S

scorpion53061

Cor,
This will work but I am sure it will only work on my machine. Do you have
any idea on how to make this work on other machines?

Try
regKey =
Registry.Users.OpenSubKey("S-1-5-21-1343024091-706699826-854245398-500\Softw
are\Microsoft\Internet Account Manager\Accounts\00000001", True)
ver = regKey.GetValue("SMTP Server")
MsgBox(ver)

Catch ex As Exception
MsgBox(ex.ToString)
regKey.Close()
Exit Sub
End Try
regKey.Close()
Exit Sub
 
S

scorpion53061

I think the answer is to loop through USER and find the value of "SMTP
Server" and then grab its value.
I will try to write this........if anyone wants to help please jump in......
 
S

scorpion53061

Will this code return the smtp server on Windows 98, Me, 2000?
Any other things I should know?


Try
regKey =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Internet Account
Manager\Accounts\00000001", True)
ver = regKey.GetValue("SMTP Server")
MsgBox(ver)
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString)
regKey.Close()
Exit Sub
End Try
regKey.Close()
Exit Sub
 
F

Fergus Cooney

Hi Scorpion,

When I looked in my registry under
HKCU\Software\Microsoft\Internet Account Manager\Accounts\
I found 00000007, 8, 9 etc, but no 00000001.

The earlier ones were deleted. Of the ones that are there, some are for
mail and some are for news.

The good news is that there is a key
HKCU\....\Internet Account Manager\Default Mail Account
which gives the account number as a string. In my case it's 00000007.

The code below worked for me (on Win2000).
Perhaps some others could try it out.

Regards,
Fergus

<code>
Dim regKey As RegistryKey
Dim sSmtpServer As String
Try
regKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Internet Account Manager", False)
Dim sMailAccount As String _
= regKey.GetValue ("Default Mail Account")
regKey.Close()

regKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Internet Account Manager" _
& "\Accounts\" & sMailAccount, False)
sSmtpServer = regKey.GetValue ("SMTP Server")

Catch ex As Exception
MsgBox(ex.ToString)
Finally
If Not regKey Is Nothing Then _
regKey.Close()
End Try
</code>
 
S

scorpion53061

Fergus,
You were dead on balls accurate here. ......:) Thank you for your help.....
 
C

Cor

Hi Fergus,
It works as a fish in the water,
Four little changes, not real in the code, but if you want to show it
others, I think you tested it in the debugger.
imports microsoft.win32
....
Dim regKey As RegistryKey
Dim sSmtpServer As String
Try
regKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Internet Account Manager", False)
Dim sMailAccount As String _
= regKey.GetValue ("Default Mail Account") ..toString
regKey.Close()

regKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Internet Account Manager" _
& "\Accounts\" & sMailAccount, False)
sSmtpServer = regKey.GetValue ("SMTP Server") ..toString
messagebox.show(sSmtp.Server)

Catch ex As Exception
MsgBox(ex.ToString)
Finally
If Not regKey Is Nothing Then _
regKey.Close()
End Try
</code>
Nice it is in my snippets
Cor
 
S

scorpion53061

Cor I didnt see anything change what did you change?

One thing I observed on some of my Windows 98 machines here at work (we use
groupwise for an email client) is that the value "Default Mail Account"
didnt exist. I am assuming that an SMTP Server then would not exist would
you agree? I handled it in the Catch and Finally but......

If a user used Outlook and never used Outlook Express do you suppose the
values would be the same under "Default Mail Server". The reason I ask is I
noticed it listed my Outlook Express email and not my Outlook information
though it is my "default" email account.
 
F

Fergus Cooney

Hi Cor,

I have a whole pile of Imports from all the snippet development so
sometimes I forget to copy them out. And Option Strict On had been commented
out for something else and left that way. Oops! ;-)

Cheers for the additions.

Regards,
Fergus
 
F

Fergus Cooney

Hi Scorpion,

Cor added the Imports, which you already have. He also added .ToString to
my GetValue()s which is necessary when you have Option Strict On. (You don't
use it, I believe, so the call to ToString would get done through
late-binding).

He also put back the MsgBox which I hadn't shown (my version was a
function and the caller did the showing).

Unfortunately I don't know Windows 98 and don't use Outlook (2000) for my
email so I can't answer the important questions.

Regards,
Fergus
 
S

scorpion53061

That i s ok. I am thinking of just making it a requirement that IIS be
installed to use the program. That will solve the issue I think.

You done great.
 
S

scorpion53061

well I got my butt roundly kicked by my coworkers because if the user has a
email account other than Outlook Express or possibly Outlook it will not
pick up the SMTP Server.
Any thoughts on this?
(By the way they didnt have ANY suggestions to contribute.)
 
F

Fergus Cooney

Hi Scorpion,

|| well I got my butt roundly kicked by ...
|| Any thoughts on this?

Are there any friendly young ladies handy with the massage oil?


|| (By the way they didnt have ANY suggestions to contribute.)

Of course not, that would be too helpful. ;-)

What others are they talking about? Is there any chance of getting hold of
one these and installing it with Windows on a nice new partition (ie. no
Outlook and an uncluttered Registry) and seeing what it puts in the Registry?

Regards,
Fergus
 
S

scorpion53061

basically what they are saying is any other email client besides Outlook
Express this will not work with.

No unfortunately they are all guys and to be honest they are all very much
the anti - .NET. I am the lone .NET guy here and it can cause some friction
at times. But they usually are a good group of guys.

I did some checking on the new computers here.

None of the XP machines had IIS automatically installed (we only buy Pro) .
None had a default email server key. After the install of that the values as
we have them currently coded appear though they are empty.

I intialized the Outlook Express install and the values were filled with
what I entered in the wizard.

I didnt have a copy of Office I could use to to test with Outlook.

I have a feeling they are right ......... :(
 
S

scorpion53061

This is the email the senior guy here sent me today. He was a little on the
crabby side.................

(There is no such thing as one or even any default location. No Windows
operating system requires a user to define a default smtp server and there
is
no default location in the registry for such information to be stored when
the
user does define a default smtp server.

HKCU\Software\Microsoft\Internet Account Manager\Accounts is the default
where:
a) the user is using Outlook Express,
b) has configured an smtp server,
c) is using the default identity,
d) has made no changes to the keys used by Outlook Express.
This is regardless of the operating system in use be it Win 98, Win Me, XP,
Win 2K or Win Server 2003. So if those conditions will be met then you're
OK.

Therefore you need to consider those who:
a) Use Hotmail, Yahoo or other web based e-mail,
b) Use another mail client such as Agent, Pegasus or Eudora. For example
Agent
stores the information in the file AGENT.INI in the Agent message store. I
don't currently have a PC here with Outlook installed so cannot check for
you
where Outlook stores this information.
c) Use Outlook Express but no longer use the original default identity in
which case the account information is held in the key
HKCU\Identities\{CLSID}\Software\Microsoft\Internet Account Manager\Accounts
In my case although I have only a single identity I use the above key rather
than that in HKCU\Software as this enables me to transfer the account
information together with that for the rest of Outlook Express from
operating
system instance to instance and between machines as and when required. The
same is true of many other beta testers.

I realise that I have barely scratched the surface of the various
possibilities. I hope that if nothing else this thread has made you think
again about
how a simple question doesn't always have a simple answer and that there can
often be a number of different answers.)
 
F

Fergus Cooney

Hi Scorpion,

Something of a heavy blow there. Just the first point - a) web-based
email - throws a major spanner in the works!

Whoever gave you that bit of the spec is going to have to rethink their
requirement. You can create miracles - but not a galaxy of them.

Good luck on this one - and better lucj on the next task. ;-)

Regards,
Fergus
 
S

scorpion53061

yeah I would be just satisfied with those with POP3 accounts of being
certain I would get their defaults correctly.
I think I am going to go ask the boss if he will let me just ask the user
and store the value in a xml file.
I have spent way too much time on this........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

can't send or receive emails- 2
can't send mail 1
Trouble Setting up .... 1
Balance Due??? 12
error in receiving messages. 1
Can't send messages 7
error# 0x800CCC0E 1
I can receive e-mail but i can't SEND 17

Top