Sending mail with VB.Net

This may ultimately be an SMTP admin question (as opposed to VB.Net) but, I wrote the following code to send a mail messge from a VB.Net app.

      Dim from As String = "dexterm@mindspring.com"
      Dim mailto As String = "dexterm@mindspring.com"
      Dim subject As String = "Test Message"
      Dim body As String = "Can you see this"

      SmtpMail.SmtpServer = "localhost"
      SmtpMail.Send(from, mailto, subject, body)

I don't know a lot about SMTP but it appears to be working; at least, I don't get any error messages inside the try/catch.  I looked at the SMTP mail queue "C:\inetpub\mailroot\Queue" and all of the messages appear to be "stuck" there.

1st question - why aren't the messages getting sent   Is there some option I need to check in IIS or SMTP
2nd question - Is SMTP the protocol that Microsoft Outlook and other mail apps use   If I were to distribute this app, I can't assume that the user has SMTP can I

Thanks in advance for your help

Dexter McCloud


Answer this question

Sending mail with VB.Net

  • marklar

    thanks I'll dig around in the SMTP/IIS properties!
  • Guillermo Roldán

    Erik:

    I don't see how this is conflicting with what I suggested. That is, you need a mail server. In my case, since I'm working offline, I have to connect. If you're running connected, it will just see the mail in the queue and send it. But in any case, you have to have a mail server to process the mail. The SMTP service doesn't actually perform any routing, as far as I know, and that was my point. 

  • Jose Ann Roche

    Sounds like a configuration problem in IIS.  There are a million problems you can run into with SMTP in IIS if you don't know what you're doing (I know I don't)  ;)  Basically, SMTP in IIS just acts as a channel to pass the mail off to a real mail server that knows what it's doing (anything that supports SMTP and is a mail server, like Exchange, etc).

    I don't have IIS in front of me so I don't remember the exact location of where it is in SMTP, but just go into the properties and make sure you have the host set to a "real" mail server that accepts anonymous (or authenticated if this is for your company or something) SMTP messages.  Your code is fine and works, it's just your configuration sounds a little whacked.

    Good luck!

  • Lovie

    and I'm back.....

    Here's what the problem was - there is an option in SMTP properties called "Smart Host".  Here you are suposed to specify the name of your ISP's SMTP server; otherwise, it will get stopped at the gate.  On top of that, in my software, I was explicitly specifying the name of my SMTP server as "localhost".   Using SMTPMail, if you DON'T specify the SMTP server, it will find the default SMTP server.

    Once I got those two issues resolved, I was able to send mail from my VB.Net app.

    Thanks for your help

  • johnninan

    hhhhmmm...I'm not so sure about that...the last place I worked at, we had SMTP setup in IIS and had it's host set to our Exchange Server.  When we used SMTP from a web page, it would drop them into the drop folder (on the web server still) and then exchange would pick it up and actually do the sending of it (but that was automatic stuff) and it worked just fine.
  • Squig

    In other words, unless you can guarantee that your users have access to an SMTP mail server (such as Exchange), you may need to look into other alternatives for sending mail. And there are some out there -- check <a href="http://www.componentsource.com">http://www.componentsource.com</a> for information on .NET mail components. I found about 10 or so available when I searched there.
  • Scott Gunn

    yah, Smart Host, that's what it is...i couldn't remember the setting!  That's pretty neato that it'll find a default if you don't specify it.  Come to think of it, I've never specified it, so that makes sense.  Glad you got it!
  • Christopher Lusardi

    As far as I know, the SMTP service on your machine just submits the messages to a mail server. That is, in my case, messages I send this way don't "go" until I connect to Exchange to send them. If I'm working disconnected from Exchange (even if I'm connected to the internet), the messages don't "go" until I actually connect to Exchange and attempt to send/receive mail. The SMTP service, as far as I know, has no information about connecting to the Web and actually distributing mail. 
  • brrrr

    I guess technically you're right.  Sorry about that.  It just stores them for pickup by a "real" mail server.

    I was just saying that I think the problem in dexterm's case, is that nothing is setup to "pick it up" and send it from SMTP in IIS.

  • halola

    did you look at the SMTP Properties in the IIS MMC   Somewhere, there's a host property on one of the tabs (and then i think you hit a button towards the bottom, like advanced or something to get to it) and set the host to an SMTP server that will accept the mail, like your ISP's SMTP server or your company's exchange server, etc and it should work.  the localhost SMTP server just needs to know what's going to be delivering the e-mail for it.
  • Vishal Mistry

    thanks guys...

    well as far as connecting to Exchange, I ran my app both with Outlook running and offline.  I can "see" that my code is working because the message goes into C:\inetpub\mailroot\Queue.  However, it nevers gets OUT of the queue (i.e. actually getting mailed to the recipient).

    I downloaded a free SMTP component by SoftArtisans and compiled their VB sample.  Amazingly enough, I had written my code in the exact same manner.  Running their code ended up with the same results.

    I then stopped and restared the SMTP Service in the hope that it would search the queue at startup and try to "catch up".  However, to no avail...

    So, obviously it's my configuration but I have no idea where to look :-(

  • Sending mail with VB.Net