Sending email in vb2005

Does anyone have a barebones example of how to send email using vb 2005?
I keep having problems assigning a recipient address.
[130 byte] By [jomilton] at [2007-12-16]
# 1

Try this...

'Imports System.Web.Mail at top of module.

'System.Web.Mail.MailMessage

Dim oMsg As MailMessage = New MailMessage

oMsg.From = "noone@nobody.com"

oMsg.To = "someone@somewhere.com"

oMsg.Subject = "Email Demo"

oMsg.Body = "This is the main body of the email"

SmtpMail.Send(oMsg)

Meadensi at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
I'm quite new to this so please bear with me. I'm also trying to the above, but cant find the System.Web.Mail to import. Is this becuase I'm writin a windows form and not a web page? If so what do I need instead?
Ja1970 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
The System.Web.Mail classes have actually been made obsolete in 2005. You can still use them; they're just not considered the preferred way of sending mail for a variety of reasons. If you'd like to use the above sample, you'll need to add a reference to System.Web.dll.

Alternatively, you can use the System.Net.Mail classes to do the same task (no additional references required). Here's a quick sample:


Dim mailClient As New System.Net.Mail.SmtpClient
mailClient.Send(
"from@address", "to@address", "subject", "message body")

I hope this helps!

Joe
The VB Team

Joe_MS at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

How do I now specify a SMTP host? I'm getting the following error.

System.InvalidOperationException was unhandled
Message="The SMTP host was not specified."
Source="System"
StackTrace:
at System.Net.Mail.SmtpClient.CheckHostAndPort()

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at System.Net.Mail.SmtpClient.Send(String from, String recipients, String subject, String body)

...............

Ja1970 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
The SMTPClient class has a constructor that takes a host.

eg.


Dim mailClient As New System.Net.Mail.SmtpClient("smtphost")
mailClient.Send("from@address", "to@address", "subject", "message body")

Toddap_MS

Toddap at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
Hi Joe, I see that you say "System.Web.Mail classes have actually been made obsolete in 2005" can you direct us to a walk through that would be up to date? for sending mail with visual Studio 2005? THanks
djchapin at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7
I should have added that I didn't see the System.Net.Mail.SmtpClient in the object browsers so I'm not clued in..thank
djchapin at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8
Big Smile I have it now guys. Take a look at this...


Dim
mailClient As New System.Net.Mail.SmtpClient(StrSmtpHost)
'place the name of your smtphost in quotes in StrSmtpHost

mailClient.Send(StrSenderAddr, StrRecipientsAddrs, StrSubject, StrBodyMessage)
'all of the parameters here are strings

Ja1970 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 9

When I use the above the email sends fine, however doesn't put anything in my "sent items" box. Is there a generic way to do this for any client?

If not I'm using outlook, is there at least a way to do it for that?

Ja1970 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 10
Hi-

Unfortunately, no, there is no generic way. To date the "Sent Items" feature is something built in to the e-mail client software. You would need to roll your own way in the client you're writing.

Best,
Paul

PaulYuk_MS at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 11

I have an error message, it is Failure to send email with same code

Dim mailClient As New System.Net.Mail.SmtpClient("smsmsg.net")

mailClient.Send("?@smsmsg.net", "?@hotmail.com", "Test Send via VB2005", "Ok")

what is the problem?

Romantic_touch at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 12

For a bare bones example, check out the code snippets. There is one under Networking for sending email. It generates the following code:

Dim message As New MailMessage("sender@address", "from@address", "Subject", "Message Text")

Dim emailClient As New SmtpClient("Email Server Name")

emailClient.Send(message)

Jim Wooley

jwooley at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 13

I had used code snippets but I faced same error message also

(Faulire Sending Email)

Romantic_touch at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 14

I have a question about the smpthost. First off what is it? can it be an IP?

Thank you

Monkletx1 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...