Email is not getting sent to Office365 Email account

Does anyone know why my office365 email account works from inside our domain but does not work from our DMZ server?

Email sent from DMZ server to recipients with exchange account works fine.

However, users are not receiving emails sent to our office365 email account.

I have tried using my domain account but it does not work. I also tried using the DMZ server account but that does not send email either.

Any ideas?

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
        'Address of email sender
        Dim ccEmail As String = txtemail.Text

        'Create the msg object to be sent
        Dim msg As New MailMessage()

        'Add your email address to the recipients
        'Configure the address we are sending the mail from
        Dim fromEmail As New MailAddress(ccEmail)
        msg.From = fromEmail
        'Append their name in the beginning of the subject
        msg.Subject = "Testing Office365 email account"

        'To embed image in email
        msg.Body = "If you receive this email, then office365 email account is working from DMZ server"
        '   msg.Attachments.Add(New Attachment(New MemoryStream(bytes), lblEmpName.Text & DateTime.Now.Ticks & ".pdf"))
        msg.IsBodyHtml = True

        'Configure an SmtpClient to send the mail.
        Dim client As New SmtpClient("")   'Exhange IP Address
        client.Host = ""
        client.Credentials = New System.Net.NetworkCredential("dmzuser", "mydmzpassword")
        'client.DeliveryMethod = SmtpDeliveryMethod.Network
        client.EnableSsl = True
        client.Port = 25
        'Send the msg
        lblMsg.Text = "Success!"
    End Sub

Open in new window

Thanks in advance
LVL 29
Who is Participating?
Gaurav SinghSolution ArchitectCommented:
if you are using 0365 SMTP server in your script, it wont work, you need to create relay account in 0365

David Johnson, CD, MVPOwnerCommented:
check your exchange transport logs
sammySeltzerAuthor Commented:
Creating a relay on 0365 solved it for me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.