Setting SMTP server?

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
hi, how to set the SMTP server on my computer?
I am using IIS from Windows...
Thanks a lot...
I just wanna try to set the SMTP server for sending email from VB. Net app.
Due the server problem, coz my home comp doesn't have any SMTP server.
The error is "Can't connect to the server"
 

Mykre

Active member
Joined
Jun 14, 2004
Messages
28
Location
Australia
Programming Experience
3-5
Try This,

--------------------------------------------------------------------
Private Sub Page_Load(sender As Object, e As System.EventArgs)
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here
SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here
SmtpMail.Send(mail)
End Sub 'Page_Load
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
I too would like to know how to set (configure) the SMTP server on my computer. Writing the code that sends the email is pretty straight-forward, thanks for the example.

How do I know the server name? (SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here). What is my real server? How do I find it (or set it)? I've tried mail. + the URL to my webserver, to no avail.

I open the IIS dialog (it says 'Internet Information Services' at the top of the window, task manager calls it mdm.exe); the SMTP server is named 'SMTP Virtual Server'; I right click it and select properties; nowhere in the properties dialog is a setting that resembles 'mail.mycompany.com'.

Is the MailMessage.Fields property in the V1.1 framework? I use V1.0 and their is no Fields property for the System.Web.Mail.MailMessage class.

When I try to run the code (without the Fields lines) I get an error that says "Could not access 'CDO.Message' object.

Perhaps this isn't the forum to ask this, but any help would be appreciated.
 
Last edited:

Mykre

Active member
Joined
Jun 14, 2004
Messages
28
Location
Australia
Programming Experience
3-5
You will need to make sure that you have SMTP installed on the server machine.

If you are running Win2k and above you will need to have IIS installed and the smtp components that go with it. Then you will have to make sure that you company or systems will allow the smtp traffic to flow from the machine you have the server installed on.

With a company that uses Exchange, you will have to set the server address in the code to the address of the exchange server. If the exchange server allows the sending of anonymous smtp (smtp Relay agent, which is a security hole and an outlet for spammers to milk off) then you will not have to pass the user name and password. If the exchange server requires the user to be authenticated on the server you will need to set the user name and password.

"Could not access 'CDO.Message' object

This could mean that the messaging systems are not installed on your PC, You did make sure that you added a refferance to the system.net.mail classes to you project.

Mykre,
 
Last edited:

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Thanks for the reply.

But I did state that I could open the IIS dialog and see the SMTP server (and yes it is started). This would obviously mean that I have SMTP installed.
I can also run the app which means that I do have the correct references.

The question again is: How do I know the name of the SMTP server (SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here). What is my real server?

How about the fields property? In my object browser, there is no fields property and I also get the blue underscore in the code window; when I rest the cursor over it, the tooltip states that there is no Fields property for the MailMessage class.
 

AmesVB

Member
Joined
Jun 14, 2004
Messages
5
Programming Experience
10+
If it is installed on your computer and you are running the code on your computer use "localhost".

So use this line of code:
SmtpMail.SmtpServer = "localhost"

If you are wanting to send through another computer on your local network just use it's ip. You can find that by going to the machine, opening a dos box, and typing "ipconfig", without the " of course.
 
Top Bottom