specify the mail server address

yulyos

Well-known member
Joined
Jun 4, 2004
Messages
67
Location
Israel
Programming Experience
5-10
Hi,
I copied this code from web site:
http://www.systemnetmail.com/faq/2.1.aspx
VB.NET:
Sub PlainText() 
'create the mail message 
Dim mail As New MailMessage() 
'set the addresses 
mail.From = New MailAddress("[EMAIL="me@mycompany.com"]me@mycompany.com[/EMAIL]") 
mail.To.Add("[EMAIL="you@yourcompany.com"]you@yourcompany.com[/EMAIL]") 
'set the content 
mail.Subject = "This is an email" 
mail.Body = "this is the body content of the email." 
'send the message 
Dim smtp As New SmtpClient("127.0.0.1") 
smtp.Send(mail) 
End Sub 'PlainText
My question is:
How can I get these numbers:
VB.NET:
Dim smtp As New SmtpClient("127.0.0.1")
Thanks in advance
 
MSDN to the rescue
http://msdn2.microsoft.com/en-us/library/k0y6s613.aspx






Parameters

host

A String that contains the name or IP address of the host computer used for SMTP transactions.

Remarks
The host parameter is used to initialize the value of the Host property. The Credentials and Port properties are initialized by using the settings in the application or machine configuration files. If host is a null reference (Nothing in Visual Basic) or equal to String.Empty, Host is initialized using the settings in the application or machine configuration files.

For more information about using the application and machine configuration files, see mailSettings Element (Network Settings). If information is specified using SmtpClient constructors or properties, this information overrides the configuration file settings.
 
Last edited:
The server is the PC in which the SMTP client resides.

If your email is hosted by another company you would put the SMTP information as the server.

For example: (smtp.hotmail.com) <-- use your SMTP server here. Whoever provides your email can tell you this.
 
This is working.
Dim smtp As New SmtpClient("smtp.internet service provider")
'
But I want to give the program to my friend and he will send me an Email From my program.
The program need to know the ("smtp.internet service provider") of my friend.

Do you know the code to find the ("smtp.internet service provider")
 
I'm sorry, I don't know how else to explain it. Your friend needs to find out his own SMTP server and tell you what it is.

This is of course, if your friend knows your are putting this program on his computer.
 
There may be something in .NET 2.0 that will pull this information for you, but I am not that familiar with 2.0. Perhaps someone else can point you in the right direction.
 
If the SMTP server is installed on the machine running the code then the IP address is 127.0.0.1. It is most likely that your friend will not have a SMTP server installed, especially if they don't know the host name. There is no way, if you think about it, for the framework to tell what SMTP server your friend is using.
One way to provide that functionality is to open an email using Process.Start which will use the default email client. You could also use the SMTP server that is working for you ("smtp.internet service provider")
 
yulyos, have you ever used a email application that discovers the user account and connection settings by itself? NO. The user always have to input their own confidential account settings before operating such software. When you write software you must take this into consideration and provide interface for user to input the account data, save it securely, and retrieve it other places in application when needed.
 
Back
Top