cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Sending Emails using Office365.SendEmail()

I want to send the email when a SharePoint list item is added and have several questions on how to process.

  1. I found that I can connect to Office 365 Outlook and use Office365.SendEmail() function which is pretty simple. The only question here is what is better in terms of which practice seems to be accepted or works the best. Compared to Sending Emails with using Microsoft Flow on PowerApp event, Microsoft Flow on SharePoint list event or sending within PowerApp using Office365.SendEmail(). Is there benefits of using one option over another?
  2. I have trouble getting email from a field. The field is People/Group in SharePoint. I have this function in the OnSuccess trigger of the form:
    Office365.SendEmail(DataCardValue17.Selected.Email,"TEST","TEST");Navigate(MainPage,ScreenTransition.Fade); ResetForm(FormCreateTravelRequest)

    When I run the app and the form I get the following error on the Office365.SendEmail() function:
    The service returned an error: Office365!SendEmail: The method ‘SendEmail’ has an invalid value for parameter ‘To’
    Here is the pic:
    issue1.png
    Now I thought maybe it is not pulling the email correctly from the form field, to test that out I created the Label1 and its text changed to:
    DataCardValue17.Selected.Email

    It appears to show the correct email. To test if it would work I changed the OnSuccess function to:
    Office365.SendEmail(Label1.Text,"TEST","TEST");Navigate(MainPage,ScreenTransition.Fade); ResetForm(FormCreateTravelRequest)

    I tried to run it again and now I get this error:

     

     

    The service returned an error: Office365!SendEmail: {“status”:404,”Message”:”User account does not exist”,”source”:”127.0.0.1”}
    Here is a pic:

     

    issue2.png

    I thought maybe its because it has mail.onmicrosoft.com suffix, even though I tried to send myself an email with the mail.onmicrosoft.com and it worked same as just using my real email address. To remove that I changed the text function of the label to:

    Substitute(DataCardValue17.Selected.Email,"mail.onmicrosoft.com","ca")

     

    However, this still produces same error (User account does not exist)

    So now I am at a loss, what I am doing not right when trying to send the email?

  3. I want to send a complex HTML email. How would I have to change the Office365.SendEmail() to do that?

    Is writing this function enough?

     

    Office365.SendEmail(Label1.Text,"<b>HTML TEXT</b><br><em>Hello World</em>","TEST",”isHtml:true”);

     

    Does it matter that I put all HTML in the Office.SendEmail() function, would it be better if I added an HTML text control and made it hidden and then just linked it to the function?

Any help really appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
AlexisHA
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

Hey there you can use concat function to solve it. Save your mail in a Collection and Office365.SendEmail(Concat(Mail;Email;";");"TEST";"TEST").

 

It works ^^

View solution in original post

13 REPLIES 13
Community Support Team
Community Support Team

Re: Sending Emails using Office365.SendEmail()

Hi @Anonymous,

 

This sounds like the Office 365 Outlook service error. Please take a try to switch to a testing account (different email format, take a try with the free trial) and check to see if that would work.

 

I just tested the following code:

Office365.SendEmail(DataCardValue12.Selected.Email,"Text","Test")

It works from my side, I received the corresponding Email.

the format of the testing Email account is the following:

name@Company.onmicrosoft.com

 

Besides, to send the Email in HTML format, please try the following format:

Office365.SendEmail(
          DataCardValue12.Selected.Email, // To field
           "Text",                        //  Subject Field
           "<b><font color=blue>HTML</font></b>text"           // Body Field, this could also be HtmlText1.HtmlText     
           {IsHtml:true}                  // the record elements for other parameter          
       )

2.PNG

Function reference:

4.PNG

Office 365 Outlook

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Re: Sending Emails using Office365.SendEmail()

@v-micsh-msft Thanks for the reply really appreciate that! Do you know what could be the problem with the Office 365 Outlook service or how to fix that? Also, are there other options to send email? 

Anonymous
Not applicable

Re: Sending Emails using Office365.SendEmail()

I went ahead to do some testing and tried to create the email sending with the Flow.

 

I set up my Flow to activate when the new item is added to SharePoint site. Whenever I try to run the flow I still get the same User account does not exist. I asked around my colleagues about our email system. We are using Sherweb service, would that be the issue as we are not using Exchange? If so, are there any work arounds?

 

Also I tried to set up email with using simple Mail datasource from PowerApps. I tested it our by writing

Mail.SendEmail(Label1.Text,"TEST",HtmlText3.HtmlText,{ishtml:true})

However I get the following error:

 

 

The service returned an error: Mail!SendEmail: The method 'SendEmail' has an invalid value for parameter 'to'

But the email in Label1.Text is correct.

When I did this:

 

 

Mail.SendEmail("myemail@company.com","TEST","TEST")

I did recieve the email. But that does not allow me to dynamically change the email or the body of the email.

 

Adi2ro
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

It happened to me as well. It's an issues with the Studio Only. When you are in edit mode, if you navigate to that screen without actually selecting the dropdown, it doesn't "see" the value, even though the same value in a label works. So you can either make a label take the value and then import the value from the label in the Office365.SendEmail syntanx OR just try the app and it will work.

 

I have noticed that there are some diferences between using the Studio and the Live app. In studio sometimes the values are not imported properly while using the app live, works as it should.

 

See if using the app by Opening it, will still cause the error , if yes, try the solution with the label and using Label.Text to import that value into the email.

 

I still strugle with another part: If I have two labels and one is blank, how can I use the TO field without using If's ... since if one is blank, the entire syntax fails as it cannot process blank values when sending the data to Office 365 Exchange for the TO Field. 

 

Good luck!

Jasonkatz424
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

I found that using a flow button works.

Sru
Level 8

Re: Sending Emails using Office365.SendEmail()

Hi @v-micsh-msft

 

will it work if i use a sharepoint people picker with multiple selections? or if it has a sharepoint group name choosen

 

Thanks,
Sru

tomgardzinski
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

Did anyone get any resolve to this issue without using MS Flow?

I am the creator of an app and the Office365.SendEmail seems to work for me, but when I expand testing to other individuals in my organization they receive the error:

         "Office365.SendEmail failed: The method 'SendEmail' has an invalid value for parameter 'To' "

 

I've verified all connections are made in the powerapps, and access has been granted to the SP list.

 

Any thoughts @v-micsh-msft

 

sendemail error.JPG

JMAFO
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

Did you ever find the solution to this?

tomgardzinski
Level: Powered On

Re: Sending Emails using Office365.SendEmail()

I used MS Flow to handle all emails. In general, MS Flows greatest asset is to perform an action based off a trigger. That trigger being selecting a button in a powerapp, then let Flow handle the action. I find that using that structure cleared the errors.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,943)