Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How Can I Send Direct E-Mails?
Message
From
06/12/2006 14:12:19
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01175187
Message ID:
01175342
Views:
7
>Is there a way to send an E-Mail (using VB.Net 2005) directly to a recipients E-Mail server, without the need for an intermediate server?

You might need to adjust some of that:
Imports System.Net.Mail
Imports System.IO

        Public cBCC As String = ""
        Public cBCCName As String = ""
        Public cBody As String = ""
        Public cCC As String = ""
        Public cCCName As String = ""
        Public cFile As String = ""
        Public cFrom As String = ""
        Public cFromName As String = ""
        Public cPort As String = ""
        Public cSMTP As String = ""
        Public cSubject As String = ""
        Public cTo As String = ""
        Public cToName As String = ""
        Public lHtml As String = True

        ' Send an email
        Public Function SendEmail() As Boolean
            Dim lcEmailAddress As String = ""
            Dim llSuccess As Boolean = False
            Dim lnCounter As Integer = 0
            Dim loAttachment As Attachment = Nothing
            Dim loEmail As MailMessage = New MailMessage
            Dim loEmailAddress As MailAddress = Nothing
            Dim loSMTP As SmtpClient = New SmtpClient

            lcEmailAddress = cFromName + " <" + cFrom + ">"

            ' From
            Try
                loEmailAddress = New MailAddress(lcEmailAddress)
            Catch loError As Exception
                oApp.ErrorSetupControlledByTheFramework("The email " + lcEmailAddress + " is invalid.")
                Return False
            End Try

            loEmail.IsBodyHtml = lHtml
            loEmail.From = loEmailAddress

            ' To
            For lnCounter = 1 To oApp.ParmCnt(cTo)
                lcEmailAddress = oApp.GetParm(cToName, lnCounter) + " <" + oApp.GetParm(cTo, lnCounter) + ">"

                Try
                    loEmailAddress = New MailAddress(lcEmailAddress)
                Catch loError As Exception
                    oApp.ErrorSetupControlledByTheFramework("The email " + lcEmailAddress + " is invalid.")
                    Return False
                End Try

                loEmail.To.Add(loEmailAddress)
            Next

            ' CC
            If cCC.Length > 0 Then
                For lnCounter = 1 To oApp.ParmCnt(cCC)
                    lcEmailAddress = oApp.GetParm(cCCName, lnCounter) + " <" + oApp.GetParm(cCC, lnCounter) + ">"

                    Try
                        loEmailAddress = New MailAddress(lcEmailAddress)
                    Catch loError As Exception
                        oApp.ErrorSetupControlledByTheFramework("The email " + lcEmailAddress + " is invalid.")
                        Return False
                    End Try

                    loEmail.CC.Add(loEmailAddress)
                Next
            End If

            ' BCC
            If cBCC.Length > 0 Then
                For lnCounter = 1 To oApp.ParmCnt(cBCC)
                    lcEmailAddress = oApp.GetParm(cBCCName, lnCounter) + " <" + oApp.GetParm(cBCC, lnCounter) + ">"

                    Try
                        loEmailAddress = New MailAddress(lcEmailAddress)
                    Catch loError As Exception
                        oApp.ErrorSetupControlledByTheFramework("The email " + lcEmailAddress + " is invalid.")
                        Return False
                    End Try

                    loEmail.Bcc.Add(loEmailAddress)
                Next
            End If

            loEmail.Subject = cSubject
            loEmail.Body = cBody
            loSMTP.Host = cSMTP
            loSMTP.Port = cPort

            ' If we have an attachment
            If cFile.Length > 0 Then
                For lnCounter = 1 To oApp.ParmCnt(cFile)
                    loAttachment = New Attachment(oApp.GetParm(cFile, lnCounter))
                    loEmail.Attachments.Add(loAttachment)
                Next
            End If

            Try
                loSMTP.Send(loEmail)
                llSuccess = True
            Catch loError As Exception
                oApp.ErrorSetup(loError)
            End Try
            Return llSuccess
        End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform