office 365 sending email

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 = ""
        ToEmail = ""
        CCEmail = ""
        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 = ""
        Dim UserName As String = ""
        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
        Catch objException As Exception
            msg = objException.Message
        End Try
        mMailMessage = Nothing
        mSmtpClient = Nothing

Open in new window

pamela rizkDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Pamela,

1. Is Sender Account properly populated in AAD?
2. Are you trying to send the mail on behalf of someone? if yes, then does sending account has Send As permission?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pamela rizkDeveloperAuthor Commented:
ohh yes you are right i think this is the problem thnak you
Chinmay PatelChief Technology NinjaCommented:
Glad I could help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.