troubleshooting Question

office 365 sending email

Avatar of pamela rizk
pamela rizkFlag for Lebanon asked on
Microsoft OfficeASP.NETMicrosoft 365
3 Comments1 Solution651 ViewsLast Modified:
hi
I am having the below problem while sending email: in office 365
here are the server response was: 5.2.0 STOREDRV.Submission.Exception:
SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process
message due to a permanent exception with message Cannot submit message.
below is the code i am using:
FromEmail = "xxx@domain.com"
        ToEmail = "x1x1x1@domain.com"
        CCEmail = "x2x2x2@domain.com"
        Dim msg As String = ""
        msg = "Test Sending  Email has been Done successfully"
Dim mMailMessage As New MailMessage()

        Dim EmailSubject As String = "Test Done System"
        Dim EngineStep As String = "Sending External Email"
        Dim EmailMsg As String = ""
        Dim BodyEmail As String = ""
        Dim smtpmail As String = "smtp.office365.com"
        Dim UserName As String = "x3x3x3@domain.com"
        Dim accPassword As String = "@rabrePR2018"
        mMailMessage.From = New MailAddress(FromEmail) '** Set the sender address of the mail message
        mMailMessage.To.Add(New MailAddress(ToEmail)) '** Set the recepient address of the mail message
        mMailMessage.CC.Add(New MailAddress(CCEmail))
        mMailMessage.Subject = EmailSubject '** Set the subject of the mail message
        mMailMessage.Body = BodyEmail ' Set the body of the mail message
        mMailMessage.IsBodyHtml = True '** Set the format of the mail message body as HTML
        mMailMessage.Priority = MailPriority.Normal '** Set the priority of the mail message to normal


        Dim mSmtpClient As New SmtpClient(smtpmail) '** Instantiate a new instance of SmtpClient
        Dim basicAuthenticationInfo As _
           New System.Net.NetworkCredential(UserName, accPassword)
        mSmtpClient.Host = smtpmail
        mSmtpClient.UseDefaultCredentials = False
        mSmtpClient.Credentials = basicAuthenticationInfo
        Dim timeout As Integer = 10
        mSmtpClient.Timeout = timeout * 1000 'in milliseconds
        mSmtpClient.Port = 25
        mSmtpClient.EnableSsl = True
        Try
            mSmtpClient.Send(mMailMessage)
        Catch objException As Exception
            msg = objException.Message
        End Try
        mMailMessage.Dispose()
        mMailMessage = Nothing
        mSmtpClient = Nothing
ASKER CERTIFIED SOLUTION
Chinmay Patel
Chief Technology Ninja
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros