web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Office365Outlook.SendE...
Power Apps
Answered

Office365Outlook.SendEmail Send to a variable

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am using the Office365Outlook.SendEmail() to send an email after I Submit my form.

It keeps complaining about my VarSendTo, its looking for a text value

 

The code on my submit button looks like this:

 

SubmitForm(EditForm1)

Set(VarSendTo,AdminEmailValue);  //this is the datacardValue of my "AdminEmailAddress" Card

Office365Outlook.SendEmail(

VarSendTo,

"Subject here",  // would be nice to be able to set dynamically
"Hi User... <p> You have mail in the mail room.<p> " ,   // would also be nice to set a variable with username
{
Importance: "Normal",
IsHtml: true
}
) ;

 

)

 

 

TIA,

Joe

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    155,976 Most Valuable Professional on at

    Hi @joef ,

    You can do all of this dynamically. What type of Variable is AdminMailValue - it just needs to be text. I can help you with all of this as I do similar things.

     

  • joef Profile Picture
    on at

    Hi Warren,

    Long time no speak 🙂

     

    My SPO list has Lookup columns for the admin information.

    I choose the Company name from a drop down in the app, and when the form submits, it fills in the Admin's Name,Email and Phone number.  

    The columns in my lookup list are all single lines of text.  Will it work using the lookup columns or do i need to create a calculated column to hold the data and set the Var using that column?

     

    When I submit I Patch() a collection of scanned barcodes to my list is it possible to list all of them as well?  (I know, there is always more to puzzle 🙂 )

     

    Thank you!

    Joe

  • WarrenBelz Profile Picture
    155,976 Most Valuable Professional on at

    Hi @joef ,

    Lets deal with your first issue (the easy one) - I think the text property of AdminEmailValue is propbably AdminEmailValue.Value.

    Any drop-down/combo box will be the same. To test this, when you type AdminEmailValue. (note the "dot"), look in the panel below and you will see the valid values able to be typed in.

    Next one - user name

    There is an inbuilt PowerApps function User().FullName. If you are just using it for this function, 

    "Hi User " & User().FullName & "<p> You have mail in the mail room.<p> "

    will do the job. One thing to note if you are using this to find records matching the user, it is not delegable, however the workaround is simple - set a Variable (I do mine on App OnStart)

    Set(vUser,User().FullName)

    Your third question (I hope I have this right) - you could display the collection in a gallery.

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more. It also closes the item.

  • joef Profile Picture
    on at

    HI @WarrenBelz ,

    Ha!!  Easy one huh? LOL

    Below is my code on the submit button of my form.  

    "Selected" was my only choice, there was no value or text to choose and I got the red squiggly lines when I just type in either.

     

    I am using Patch() to submit the data into SPO, since I can have multiple barcode scans before submitting the form.

    when I run the app and try to send I get an error "sendmail failed, the method sendmail has an invalid value for for Parameter To."

    I am displaying my varSendTo in a text box and it displays my email address, do I need to wrap the variable in quotes...

    When I run it from PA studio, the email goes out to me correctly, the Patch has nothing to submit, but the email works.  

     

     

    ForAll(collectMultiscan, Patch('Mail Room APP',Defaults('Mail Room APP'),{Title: VarGuid,MultiBarcode: barcodeInfo, CompanyName:DataCardValue9.Selected, Status: DataCardValue13}));

    Set(VarSendTo,AdminEmailValue.Selected);

    Office365Outlook.SendEmail(
    VarSendTo.Value,
    "Mail Room APP",
    "Hi User... <p> You have mail in the mail room.<p> " ,//dminEmailValue
    {
    Importance: "Normal",

    IsHtml: true
    }
    ) ;

    Back()

  • WarrenBelz Profile Picture
    155,976 Most Valuable Professional on at

    Hi @joef ,

    Have you looked at your variables to see what VarSendTo is returning and what is the type of control you are getting AdminEmailValue from? If it is a dropdown or combo box, what is the Items property?

  • joef Profile Picture
    on at

    Hi @WarrenBelz ,

    Good news I was able to get the collection of Barcodes to email nicely 🙂

     

    Now back to the Harder part, loading a variable from a lookup column...

     

    The app is loading an SPO list.  The Company name is a Lookup column to another list.  When you choose the company name from the drop down, it loads phone number,email address, and Contact name all from the lookup list.

     

    All columns in the lookup list are single line of text

    All columns in my main list are "lookup"

     

    After I Patch() the collection to the list, I am setting the VarSendto = email address loaded in my list for that item.

    I don't know how to tell what the data type is except from the lists as I said above...

     

    Maybe I need to get the first or last row of what I loaded to SP?  if I Patch() 10 rows there will be 10 rows with the email address.  Is there a topX()? 

    First didn't seem to work. Or I just couldn't get it to work 🙂

     

    TIA,

    Joe

     

  • WarrenBelz Profile Picture
    155,976 Most Valuable Professional on at

    Hi @joef ,

    I am trying visualise what you have, so if I am not on track here let me know.

    I am assuming your backend is SharePoint and the problem is your problem is getting a value from a Lookup field in the main data source.

    The value type for a Lookup column text is .Value

    I will also cover your last question - FirstN is the function you need.

     

    If you get stuck, can you please share your code and where/how you use it.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item.
    If the content was useful in other ways, please consider giving it Thumbs Up.

     

     

     

  • joef Profile Picture
    on at

    HI @WarrenBelz ,

    Hope you had a nice weekend...

    Yes you are correct, SPO as back-end, and I have a lookup column that I am trying to get back into my variable.

    I have attached the code I am using, along with the list definitions.  It runs on the submit check mark on EditForm1.  "On select" Property.

    First it Patches() the data to my list, then it tries to load the variable.  I am wondering if I am trying to load the Var before it loads the list item.  I tried setting the var and SendEmail in the "on success" of EditForm1, but it didn't fire off, Since I am patching(), not submitting(Form)

    The lookup column companyName, brings the email address from the lookup list when you choose the company.  Do I have to wait for the item to fully insert and save before I can pull the email address back to the Var?  If so Is there a delay I need to use?

     

    I am now trying a different route, I added the lookup list as a data source, and now I am trying to figure out how to set the variable where:

    Lookup.companyName = DataCardValue9.Selected, which is the company name chosen from the dropdown in the app.

    as below, but that's not happy either 😞 

    Set(
    VarSendTo,
    LookUp(MailRoomAPPAdmins,'Company Name' = DataCardValue9.Selected,'AdminEmailAddress'));

     

    Why can't anything be easy 🙂

     

    Thanks again for your help,

    Joe

  • Verified answer
    joef Profile Picture
    on at

    Hi @WarrenBelz,

    I figured out my varibale issue.

     

    I pulled my Lookup list as a datasource.  

     

    I removed the Var and added a lookup as the To: ALL Good!!


    Office365Outlook.SendEmail(
    LookUp(MailRoomAPPAdmins,'Company Name' = DataCardValue9.Selected.Value , 'Admin Email Address'),
    "You have mail in the mail room ",
    "You have " & "<b>" & CountRows(collectMultiscan) & "</b>" & " Packages with the following Barcodes <p>" &
    Concat(collectMultiscan, "<b>Barcode :</b>" & barcodeInfo & "<br/>" ),// &
    //Concat(ImagesCollection, "<b>Photo :</b>" & PicContent & "<br/>") ,
    {
    Importance: "Normal",
    IsHtml: true
    }

    );

     

    Thanks,

    Now I can get back to getting the images loaded 🙂

  • WarrenBelz Profile Picture
    155,976 Most Valuable Professional on at

    Hi @joef ,

    Great to hear - I see your images commented out in the code.

    I would be interested to see what you are doing here and how you are approaching it.

    BTW weekend long gone - Tuesday morning here.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 320 Most Valuable Professional

#2
11manish Profile Picture

11manish 210

#3
Valantis Profile Picture

Valantis 167

Last 30 days Overall leaderboard