We help IT Professionals succeed at work.

office 365 sending email

632 Views
Last Modified: 2018-11-29
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

Comment
Watch Question

Chief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
pamela rizkDeveloper

Author

Commented:
ohh yes you are right i think this is the problem thnak you
Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Glad I could help.