15

I was wondering how I could send an email from within a vb application? Can any one assist in where to begin?

2 Answers 2

18

Use the SmtpClient class within the System.Net.Mail namespace

Example.

'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("xx@xx")
mail.[To].Add("xx@xx")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"

'set the server
Dim smtp As New SmtpClient("localhost")

'send the message
Try
    smtp.Send(mail)
    Response.Write("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
    Response.Write("Send failure: " & exc.ToString())
End Try
Sign up to request clarification or add additional context in comments.

2 Comments

The code is going to run on an Microsoft exchange server. Do i need to do something differently?
Im no expert in setting up exchange servers but I have plenty of applications sending mail through exchange servers like above. You obv. have to change "localhost" with your exchange servers name.
3

You can use the System.Net.Mail namespace, look it up and see if it helps. I use C# but I imagine it is similar, create a client, then a message, set params of the message and then client.Send() will send the message.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.