Share via

error sending mail

Anonymous
2022-10-24T15:10:08+00:00

i have this code ... worked fine for a long time .. but now i get the error

            This message could not be sent. You do not have the permission to send the message on behalf of the specified user.

__________________________________________________

Public Sub sendEmail(fileToSend As String, eMailStr As String, subjectLine As String, cop As String, copb As String, bodyStr As String, htmlbodyStr As String)

Dim OutApp As Outlook.Application 

Dim OutMail As Outlook.MailItem 

Set OutApp = New Outlook.Application 

Set OutMail = OutApp.CreateItem(0) 

With OutMail 

    .SentOnBehalfOfName = "******@xxx.be" 

    .To = eMailStr 

    .Subject = subjectLine 

    .CC = cop 

    .BCC = copb 

    .Body = bodyStr 

    .HTMLBody = htmlbodyStr 

    If fileToSend <> vbNullString Then 

    .Attachments.Add fileToSend 

    End If 

    .Display 

End With 

Set OutMail = Nothing 

Set OutApp = Nothing 

Exit_Here:

Exit Sub 

Error_sendemail:

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2022-10-24T15:19:37+00:00

This is not an Access issue, but an Outlook permissions issue. You apparently don't have SendOnBehalfOf rights anymore. Talk to your email administrator.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-10-25T08:37:22+00:00

    it works : i changed the code

    Dim OutApp As Object

    Dim OutMail As Object 
    
    Set OutApp = CreateObject("Outlook.Application") 
    
    Set OutMail = OutApp.CreateItem(0) 
    
    With OutMail 
    
         Set .SendUsingAccount = OutApp.Session.Accounts.Item(1)  
    
        .To = eMailStr 
    
        .Subject = subjectLine 
    
        .CC = cop 
    
        .BCC = copb 
    
        .Body = bodyStr 
    
        .HTMLBody = htmlbodyStr 
    
        If fileToSend <> vbNullString Then 
    
        .Attachments.Add fileToSend 
    
        End If 
    
        .Display 
    
    End With
    

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more