Sending email in vb2005
I keep having problems assigning a recipient address.
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)
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
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)
...............
eg.
Toddap_MS
Dim mailClient As New System.Net.Mail.SmtpClient("smtphost")
mailClient.Send("from@address", "to@address", "subject", "message body")
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
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?
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
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?
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