none
How do you do Authetication Using NTLM MSEXCHAGE 2016 VB.net RRS feed

  • Question

  • Iam using vb.net and Exchange 2016  :I want to send notifications to more than 1000 employees using the procedure below am getting an error {GETTTING ERROR Mail box unavailable 5.7.1 PRA NOT PERMITED }

    IT department are telling me that i have to authenticate using NTLM How do i do this in Vb.net OR C#

    Sub sendEmail(Optional theRecipient As String = "", Optional theCCRecipient As String = "", Optional theBCCRecipient As String = "", Optional theSubject As String = "", Optional theMailText As String = "", Optional theAuditTrailRef As Integer = 0, Optional theAuditTrailText As String = "", Optional theAttachment As String = "", Optional theReply2Email As String = "")
            Dim fromAddress As System.Net.Mail.MailAddres

    s
            Dim toAddress As System.Net.Mail.MailAddress
            Dim objMiddleTier As New GlobalDB_fxns(myConn)
       

            Dim objSMTPUserInfo As New System.Net.NetworkCredential

            fromAddress = New MailAddress(objMiddleTier.SendMailFromThisAddress)
            toAddress = New MailAddress(theRecipient)


            ' Dim mailSender As SmtpClient
            ' Change the Smtp server name on the next line
            'mailSender = New SmtpClient("mail.scangroup.co.ke", objMiddleTier.SMTPPortNumber)
            Dim mailSender As New SmtpClient()
            mailSender.Host = "mail.com"
            mailSender.Port = objMiddleTier.SMTPPortNumber '25
                mailSender.UseDefaultCredentials = False
            'mailSender.Credentials = New System.Net.NetworkCredential(objMiddleTier.SMTPUserName,objMiddleTier.SMTPUserPassword, ldap)
            objSMTPUserInfo = New System.Net.NetworkCredential(objMiddleTier.SMTPUserName,objMiddleTier.SMTPUserPassword) ', ldap)
            mailSender.Credentials = objSMTPUserInfo
            mailSender.UseDefaultCredentials = False
            mailSender.DeliveryMethod = SmtpDeliveryMethod.Network


           


            Dim message As New MailMessage(fromAddress, toAddress)

            If Not theBCCRecipient Is Nothing And theBCCRecipient <> String.Empty Then
                ' Set the Bcc address of the mail message
                message.Bcc.Add(New MailAddress(theBCCRecipient))
            End If
            If Not theCCRecipient Is Nothing And theCCRecipient <> String.Empty Then
                ' Set the CC address of the mail message
                message.CC.Add(New MailAddress(theCCRecipient))
            End If



            message.Bcc.Add(fromAddress)
            message.Subject = theSubject
            message.IsBodyHtml = True ' False
            message.Body = theMailText
            If Not theAttachment = "" Then
                Dim msgAttach As New Attachment(theAttachment)
                message.Attachments.Add(msgAttach)
            End If
            Try
                ' mailSender.DeliveryMethod = SmtpDeliveryMethod.Network
                mailSender.Send(message)
            Catch ex As Exception
                'write on the eror file
                MessageBox.Show(ex.Message, "Error Mail Not Sent")
            End Try

        End Sub



    Wednesday, December 20, 2017 3:55 AM