Avatar of pamela rizk
pamela rizk
Flag for Lebanon asked on

office 365 sending email

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

Open in new window

ASP.NETMicrosoft OfficeMicrosoft 365

Avatar of undefined
Last Comment
Chinmay Patel

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chinmay Patel

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
pamela rizk

ASKER
ohh yes you are right i think this is the problem thnak you
Chinmay Patel

Glad I could help.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy