This mail sending code snippet does not work

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

Dim message As New MailMessage("(e-mail address removed)", "(e-mail address removed)",
"Test", "Test")

Dim emailClient As New SmtpClient("localhost")

emailClient.Send(message)

The IIS server is running on the local machine.

What am I missing to make this work reliably?

Thanks for any help

Bob
 
Robert,

First of all do you need to set IIS as SMTP server, that is not standard,
you can use the Microsoft tab in the add programs config for that.

Cor
 
I'm getting back error Mailbox unavailable. The server response was: 5.7.1
Unable to relay for (e-mail address removed)
The smtp server is localhost.
The SMTP service is running on the local machine
 
Hi Cor
It was already set.
I'm getting back error Mailbox unavailable. The server response was: 5.7.1
Unable to relay for (e-mail address removed)
The smtp server is localhost.
The SMTP service is running on the local machine.

I was working the local machine where the app was residing via Radmin from
another machine on the LAN and I think maybe this is a security issue, where
I have to specify an SMTP server name, username and password, but I can't
find any info on how to code this.


Regards,
Bob
 
I also tested to use localhost using system.web.mail instead of the new
system.net.mail
I get an exception : the transport could not connect to the host when using
localhost as the smtp server. When using my mail server outside of my lan
where I am normally hosted(mail.mycompany.com) the message goes through.

There seems to be something wrong with the localhost smtp server but I can't
figure out what.
This is the code snippet I used for that test.

Dim mail As New System.Web.Mail.MailMessage()

mail.To = "(e-mail address removed)"

mail.From = "(e-mail address removed)"

mail.Subject = "this is a test email."

mail.Body = "this is my test email body"

SmtpMail.SmtpServer = "mail.mycompany.com" 'This works OK but localhost does
not

Try

SmtpMail.Send(mail)

Catch ex As Exception

MsgBox(ex.Message)

End Try




Thanks for your help.
Bob
 
Yes Cor I tried that too. But just for the heck of it I tried that again to
confirm. I used either 127.0.0.1 as the host address or 192.168.1.163.
Neither of them worked. My VERY strong suspicion is that I have something
wrong with the smtp server on this computer running under framework 2. I
recall trying to use this before I had framework 2 installed with Vs2003 and
framework with framework1.1 and system.web.mail and it worked fine. Now in
Vs2005 and fraemwork2 I am having these problems. In the last two tests I
did I found that the email messages got created in the Drop directory (two
..eml files with the date and time stamp of the time of the test). I then
retried setting the host to mail.mydomain.com and also sending a message.
That did not seem to work this time either.
Yesterday I had unistalled and reintalled the smtp server on this computer
and enabled logging.
Attached you will find a log file for today (zipped format) the test entrie
are the last few. I'm trying to figure out what the other log entries (the
hotmail ones) for today are, they just seem to repeat and I don't know why.
Also I'm behind an ISA 2004 firewall, but I'm picking up and sending my
email messages to and from my hosted outside accounts via outlook 2003 OK
and it worked fine under framework 1.1 on te host. I also double checked and
made sure to add a rule to the ISA server to allow SMTP on Port 25 to be
used outbound between the protected networks on my lan and the outside
network, although I think its redundant.

I wonder if there is any testing tools that I can use to test the workings
of my local smtp virtual server.

Thanks for your help
Bob
 
I found a document showing how to use telnet to test my virtual server
kb/286421.
I worked through it OK although I found that to get 250 responses to
everything I had to use for the FROM property of the message
myloggedinUsernam@MylanDomainName
BUT during that test the message did not end up in the destination mailbox.
Trying again
Bob
 
Back
Top