How to send mail with a sender decided on runtime
Question

Hi,

I want to implement a functionality where I want to send a mail to a group of people but the sender of the mail should be decided on the run time based on the logged-in user who will trigger the button to send mail.

I have already configured/set up the SMTP account from the service center and able to send a regular email with a specific mail address (that I have used as the Username & default sender email from settings).


When I am trying to send a mail from a different email address available within the same Microsoft 365 Account getting message that error in sending mail.

I am not sure if I have to modify some settings from the Microsoft 365 Account or something else for the same.

Any help or suggestions over it?

Thanks

Hi Nitish,

May be you can write timers or Process and get the email from user table or list where you have email id and call in bulk and then next set of email to pass in Email API.


Hope this will help you to give u idea towards your use case.



Dileep


Hello @Nitish Kumar,

Since your logic is dependent on the logged-in user, say when you log in as User A, and the Sender Email is userA@example.com, email gets sent successfully.

Now to test sending email using userB@example.com, are you logging into the application as UserB or still logged in as UserA and just modifying the sender email maybe?

It would also help if you could share the stack trace from the error logs in ServiceCenter.

Regards,

AJ

Hi @AJ. 

I don't think this is because of the logged-in user as I tried with the hardcore email as an input of sender. 

I not sure but it might be because of some problem in the SMTP user I am using as it's working fine with I am using the same SMTP user's email which was used as the username in SMTP configurations.

Just to show you this is the error(below screenshot) I am getting in the service center when trying to send mail from an email that is not the same as used as a username to configure SMTP.

Hi Nitish,

Check the email logs/error logs in the ServiceCenter of the environment to understand what is causing the error. It could be the authentication issue rather programming issue.

Regards,

Swatantra

Hi @Swatantra Kumar

No, I don't think it is anything related to Outsystems Authentication as it's working fine if I keep the value/email of the sender same as the value of username used while configuring the mail SMTP.

Below is the screenshot of the error I am getting from the service center.


Hi Nitish,

It's not the OutSystems authentication, but the Sender domain authentication issue. Check out at the error message, the exception part SendAsDeniedException

STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message 

As explained at StackOverflow, This error means the user whose credential was specified in the SMTP connection cannot submit messages on behalf of the user specified in the From and/or Sender MIME headers or the FROM SMTP command.

To resolve this, you have to get the domain authenticated. Domain authentication shows email providers that the Sender (the one configured at OutSystems email settings) has permission to send emails on behalf of other users on the sender domain.  

Regards,

Swatantra

mvp_badge
MVP

Hi Nitish,

If I understand correctly , when you send email to multiple user then you face this issues or other domain user name.

Please check once domain name should be white list these is a also one reason.


Hope this will help you.

Regards

Rahul

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.