sending email

bunze

Well-known member
Joined
Aug 4, 2005
Messages
52
Location
Adirolf
Programming Experience
1-3
How can i send emails from vb.net? Ive tried amny ways. I have already doen the import sysem.web.mail but now I need a free smtp that doesnt authentcate and then what code do i use? thanks
 
Here is the code I use:

VB.NET:
Dim message As New MailMessage

message.To = txtEmail.Text
message.From = txtFrom.Text
message.Subject = txtSubject.Text
message.BodyFormat = MailFormat.Html
message.Body = txtBody.Text

Try
   SmtpMail.SmtpServer = "127.0.0.1"
   SmtpMail.Send(message)
Catch ex As Exception
   Response.Write(ex.InnerException.Message.ToString)
End Try


As long as you are running XP Pro or higher you have access to a SMTP Server with IIS.
 
Thanks but I'm getting a problemt with the smtpmail.send line, it says cdo.message something during run time.

and the response line says it isnt declared in design time
 
This is from the framework documentation:

Example
The following example can be compiled to a console application that is used to send email from a command line. If you compile the example to a file named MailMessage.exe, use the executable file to send email as follows:

MailMessage to@contoso.com from@contoso.com test hello

VB.NET:
Imports System
Imports System.Web.Mail
 
Namespace SendMail
   Public Class usage
      Public Sub DisplayUsage()
         ' Display usage instructions in case of error.
         Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>")
         Console.WriteLine("<to> the addresses of the email recipients")
         Console.WriteLine("<from> your email address")
         Console.WriteLine("<subject> subject of your email")
         Console.WriteLine("<body> the text of the email")
         Console.WriteLine("Example:")
         Console.WriteLine("SendMail.exe SomeOne@contoso.com;SomeOther@contoso.com Me@contoso.com Hi hello")
     End Sub
   End Class

   Public Class Start
      '  The main entry point for the application.
      Public Shared Sub Main(ByVal args As String())
         Try
            Try
             Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
               Message.To = args(0)
               Message.From = args(1)
               Message.Subject = args(2)
               Message.Body = args(3)
               Try
                 SmtpMail.SmtpServer = "your mail server name goes here"
                  SmtpMail.Send(Message)
               Catch ehttp As System.Web.HttpException
                 Console.WriteLine("0", ehttp.Message)
                 Console.WriteLine("Here is the full error message")
                 Console.Write("0", ehttp.ToString())
               End Try
            Catch e As IndexOutOfRangeException
               ' Display usage instructions if error in arguments.
               Dim use As usage = New usage()
               use.DisplayUsage()
            End Try
         Catch e As System.Exception
            ' Display text of unknown error.
            Console.WriteLine("Unknown Exception occurred 0", e.Message)
            Console.WriteLine("Here is the Full Error Message")
            Console.WriteLine("0", e.ToString())
         End Try
      End Sub
   End Class
End Namespace
 
Back
Top