none
Office 365 Connection failing RRS feed

  • Question

  • Hello,

    I've built a program that runs on our network to send out emails automatically.

    Up until recently it was working fine.  Now it cannot connect to office 365.

    the function below returns "unable to connect to remote server"

    Public Shared Function SendEmail(ByVal eDocType As String,
                                            ByVal eDocID As String,
                                            ByVal eFrom As String,
                                            ByVal eFromPass As String,
                                            ByVal eTo As String,
                                            ByVal eCC As String,
                                            ByVal eBCC As String,
                                            ByVal eSubject As String,
                                            ByVal eBody As String,
                                            ByVal ePDF As String,
                                            ByVal eAttachPath As String) As String
            Try
    
                Dim SmtpServer As New SmtpClient("smtp.office365.com", 587)
                Dim Mail As New MailMessage
                SmtpServer.UseDefaultCredentials = False
                SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
                SmtpServer.EnableSsl = True
                SmtpServer.Credentials = New System.Net.NetworkCredential(eFrom, eFromPass, "OurDomain.com")
    
                Mail.From = New MailAddress(eFrom) 'EmailFrom)
                Mail.To.Add(eTo)
                Mail.CC.Add(eCC)
                Mail.Bcc.Add(eBCC)
                Mail.Subject = eSubject.Trim
                Mail.Body = eBody
                Mail.IsBodyHtml = True
    
                If ePDF.Trim <> "" Then
                    Dim sb As New StringBuilder
                    sb.Append(ePDF)
                    Dim sr As New StringReader(sb.ToString)
                    Dim pdfDoc As New Document(PageSize.A4, 20.0F, 20.0F, 20.0F, 20.0F)
    
    
                    Dim htmlparser As New HTMLWorker(pdfDoc)
                    Using memoryStream As New MemoryStream()
                        Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream)
                        pdfDoc.Open()
                        htmlparser.Parse(sr)
                        pdfDoc.Close()
                        Dim bytes As Byte() = memoryStream.ToArray()
                        memoryStream.Close()
                        Mail.Attachments.Add(New Attachment(New MemoryStream(bytes), eDocID + ".pdf"))
    
                    End Using
                End If
    
                Try
                    If eAttachPath.Contains(";") = False And eAttachPath.Trim <> "" Then
                        If File.Exists(eAttachPath) Then
                            Dim tAttachment As System.Net.Mail.Attachment = New System.Net.Mail.Attachment(eAttachPath)
                            Mail.Attachments.Add(tAttachment)
                        End If
                        Mail.Bcc.Add(eBCC)
                    ElseIf eAttachPath.Contains(";") = True Then
                        Dim eAttachPathList() As String = eAttachPath.Split(";")
                        For x As Integer = 0 To eAttachPathList.Length - 1
                            If File.Exists(eAttachPathList(x)) Then
                                Dim tAttachment As System.Net.Mail.Attachment = New System.Net.Mail.Attachment(eAttachPathList(x))
                                Mail.Attachments.Add(tAttachment)
                            End If
                        Next
                    End If
                Catch ex As Exception
                End Try
    
    
                SmtpServer.Send(Mail)
    
                Archive(eDocType, eDocID, eFrom, eFromPass, eTo, eCC, eBCC, eSubject, ePDF)
    
            Catch ex As Exception
                Return ex.Message
            End Try
            Clean()
            Return "Success"
        End Function

    Did microsoft change their security settings recently?


    Tuesday, February 26, 2019 7:00 PM

Answers

  • I figured it out.  It was a reference to an offline Server in the PDF generation text.

    • Marked as answer by ITCRP Wednesday, May 29, 2019 4:19 PM
    Tuesday, February 26, 2019 8:54 PM

All replies

  • They haven't changed anything afaik, chances are your IP got blocked. Try sending a message manually and look at the detailed error message to confirm this. Or test from a different endpoint.
    Tuesday, February 26, 2019 7:53 PM
  • I tried a simple case and it worked fine. 

    It seems to be an issue with the PDF attachment.  When I comment out that code the email sends without issue

    Tuesday, February 26, 2019 8:20 PM
  • I figured it out.  It was a reference to an offline Server in the PDF generation text.

    • Marked as answer by ITCRP Wednesday, May 29, 2019 4:19 PM
    Tuesday, February 26, 2019 8:54 PM