How to get the default SMTP Server?

G

Georges BESSIS

Hi,

I found rather simple to send mail via SMTP under VB.Net.
I use the simple code (see under) which works fine if you know the SMTP
server adress.
But I want to insert it in an App used by people who dont know about such
things.

So I need a way to determine programatically which is the SMTP server to
use. Do you have any idea on how I could get that?
Second question (similar) : Can I get the default email adress so the user
(sender) does not have to enter it?

Thanks in advance.

GB

'-----------------------------------------
' Here is my current test code
' ---------------------------------------
Dim MyMail As New MailMessage

MyMail.From = New MailAddress("(e-mail address removed)")

MyMail.To.Add(New MailAddress("(e-mail address removed)"))

MyMail.Subject = "Some subject"

MyMail.Body = "Test message via SMTP"

Dim Client As New SmtpClient

Client.Host = "SMTP.domain.fr""

Client.Send(MyMail)
 
P

Pritcham

Hi Georges

I think the problem you're going to have here is that there isn't a
default SMTP server as such. For example, at home I use two Hotmail
accounts, a gmail account, and a business account. 3 of those 4 email
addresses are set up for use in Outlook (using 2 different profiles).
So which of those 4 would class as the default SMTP server? And which
would class as my default email?

Also, as a user, I would want to be able to select which of my email
addresses is used by an application, not have it/the developer
arbitrarily decide which one to use.

If your main concern is that the end-user may not know their SMTP
address (which I know many may not be familiar with) then you could
provide instructions on how to get this info (Settings in Outlook,
contact their provider etc for example). I suppose you could try to do
some sort of lookup for the SMTP server based on the email address
domain but I think you're best off asking the user.

Other than that, you may be able to find something through the registry
but as I say, your end user may not appreciate your selection of email
address on their behalf.

Cheers
Martin
 
G

Georges BESSIS

Hi Martin,

I understand your wise point about the user willing to select the SMTP
server to be used.

With respect to your observation, I may prefer actually to setup, say, a
dropdown list of available servers, letting the user select the prefered
one.

But to do so, I still need to know how to programmatically get these SMTP
server adresses.

Any suggestion?

Thanks anyway for your kind support.

Georges
 
P

Pritcham

Hi Georges

I don't think this is going to be possible for you. If you think about
how many different mail programs people could use, discounting web
based mail, your application would have to know how each of these
applications stores it's info on account settings etc so it could
retrieve them for your app. And just because a users PC has an email
app installed, doesn't mean they use it. If you're determined to go
down this route then you could look at things like the Outlook object
model and retrieve settings from there (assuming they use outlook).

Other than that, the only way you're going to know what their SMTP
settings are is if you know the environment they're in (corporate for
example).

I honestly think you need to just ask the user for this - it's not that
big a deal for the vast majority of users these days.

HTH
Martin
 
G

Georges BESSIS

Thanks for your answer. I understand your point. What I should do, I think,
is to propose (via dropdown list for example) the available servers, and let
the user decide.

I still have (about) the same question : how do I get the list of available
servers?

Regards

GB
 
P

Pritcham

Hi

See my previous answer Georges - as I say, I don't think that this is
going to be possible unless you either a) know the users environment
(i.e what email package they're using), or b) know how each of the
potential email clients stores the SMTP info etc. I really think your
only choice is to ask the user - anything else and you're just over
complicating things for both them and you (after all, if a user isn't
experienced enough to know what SMTP server they use, how on earth are
they going to know which one to choose from a list, assuming you could
get that list in the first place).

Cheers
Martin
 

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

Top