Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. send email

send email

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcomsysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angels777
    wrote on last edited by
    #1

    i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks

    ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) ***

    function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL)
    on error resume next

    dim Mailer
    set Mailer = server.createobject("CDO.Message")
    if err.number <> 0 then
    errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
    CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
    exit function
    end if

    Mailer.From = FromName & " <" & FromEmail & ">"
    Mailer.To = ToName & " <" & ToEmail & ">"
    Mailer.TextBody = Message
    Mailer.Subject = Subject
    with Mailer.Configuration
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com"
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword"
    .Fields.Update
    end with
    Mailer.Send
    if err.number <> 0 then
    errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
    CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
    exit function
    end if
    set Mailer = Nothing
    CDOSYS_Mailer = true
    end function

    C C 2 Replies Last reply
    0
    • A angels777

      i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks

      ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) ***

      function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL)
      on error resume next

      dim Mailer
      set Mailer = server.createobject("CDO.Message")
      if err.number <> 0 then
      errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
      CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
      exit function
      end if

      Mailer.From = FromName & " <" & FromEmail & ">"
      Mailer.To = ToName & " <" & ToEmail & ">"
      Mailer.TextBody = Message
      Mailer.Subject = Subject
      with Mailer.Configuration
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com"
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword"
      .Fields.Update
      end with
      Mailer.Send
      if err.number <> 0 then
      errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
      CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
      exit function
      end if
      set Mailer = Nothing
      CDOSYS_Mailer = true
      end function

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      your posts have an edit button and a delete button. Please, please, ask your questions once only. Edit them if you need to change them, don't repost.

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      • A angels777

        i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks

        ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) ***

        function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL)
        on error resume next

        dim Mailer
        set Mailer = server.createobject("CDO.Message")
        if err.number <> 0 then
        errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
        CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
        exit function
        end if

        Mailer.From = FromName & " <" & FromEmail & ">"
        Mailer.To = ToName & " <" & ToEmail & ">"
        Mailer.TextBody = Message
        Mailer.Subject = Subject
        with Mailer.Configuration
        .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath
        .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort
        .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
        .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com"
        .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword"
        .Fields.Update
        end with
        Mailer.Send
        if err.number <> 0 then
        errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description)
        CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
        exit function
        end if
        set Mailer = Nothing
        CDOSYS_Mailer = true
        end function

        C Offline
        C Offline
        Charl
        wrote on last edited by
        #3

        Hello; This seems to rather be VBScript and not VB.Net - which do you require help with? VB.Net:

        Public Shared Sub SendMail(ByVal mailTo As MailAddressCollection, ByVal mailFrom As String, _
        ByVal mailSubject As String, ByVal mailPriority As System.Net.Mail.MailPriority, _
        ByVal isHtmlFormat As Boolean, ByVal mailBody As String, _
        Optional ByVal mailCC As MailAddressCollection = Nothing, _
        Optional ByVal mailBcc As MailAddressCollection = Nothing, _
        Optional ByVal mailFromDisplayName As String = Nothing)

                Dim msg As New System.Net.Mail.MailMessage
                For Each m As MailAddress In mailTo
                    msg.To.Add(m)
                Next
        
                If mailFromDisplayName Is Nothing Then
                    msg.From = New MailAddress(mailFrom)
                Else
                    msg.From = New MailAddress(mailFrom, mailFromDisplayName)
                End If
        
                msg.Subject = mailSubject
                msg.Priority = mailPriority
                msg.IsBodyHtml = isHtmlFormat
        
                If Not mailCC Is Nothing Then
                    For Each m As MailAddress In mailCC
                        msg.CC.Add(m)
                    Next
                End If
        
                If Not mailBcc Is Nothing Then
                    For Each m As MailAddress In mailBcc
                        msg.Bcc.Add(m)
                    Next
                End If
        
                msg.Body = mailBody
        
                Dim smtpServer As New System.Net.Mail.SmtpClient()
                smtpServer.Port = 25
                smtpServer.Host = Convert.ToString(ConfigurationManager.AppSettings("SiteSMTP"))
        
                Try
                    smtpServer.Send(msg)
                Catch ex As Exception
                    Throw New Exception(String.Format("An error occurred sending an e-mail. The error recorded was {0}", ex))
                End Try
        
            End Sub
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups