Sending email with the values of entity.Product and entity.Price RRS feed

  • Question

  • Hi all,

    I have a screen to add Listings in my Lightswitch Application. For this application, I am trying to write a code for sending email. I have a table called "Mail" in the SQL database, in which I have 2 columns - ID and Subject. The Subject has a string message - " 'kindly login to the portal to accept or reject' +entity.Price+ '' +entity.Product ". In my code, I'm trying to get the actual value of product and price but I am unable to succeed. 

    If I give the following code: 

    objMessage.EmailMessage = string.Format("Your listing for {0} was created.", entity.Product);

    and provide entity.Product here, I get the value of Product in my email. But my question is - how can we read the string in the SQL table and then substitute the actual value for 'entity.Price' and 'entity.Product' in the code?

    If I read the value of the string message from my SQL table, I'm able to see the entire string "kindly login to the portal to accept or reject' +entity.Price+ '' +entity.Product", along with the double quotes at the beginning and the end of the statement. So, Lightswitch is considering the entire statement as a string only and hence, I'm unable to replace the original values.

    Can someone help me on this? Attaching the document of my requirement here for your reference - https://goo.gl/QpV2P9


    Tuesday, April 12, 2016 6:23 AM


All replies

  • Hi all, can someone help me on the above question?


    Pauline Jeswin

    Thursday, April 14, 2016 5:09 AM
  • I'm still confused with your requirement.

    I'm don't understand the relationship between the message of "kindly login to the portal to accept or reject' +entity.Price+ '' +entity.Product" and the message of "Your listing for {0} was created.". Are these message both disaplied in your mail?

    And when do you want to replace the value on Add/Edit Listing screen? And the Product and Price value that you want to show on Add/Edit Listing screen stored in Mail Table?

    Thursday, April 14, 2016 9:32 AM
  • Hi Arnold, 

    Apologies for attaching the wrong screenshot. Here is the right screenshot of the email message that I am currently getting - 

    Here is my current code:

    If I pass a constant message in my code -  "kindly login to the portal to accept or reject" +entity.Price+' '+entity.Product;  - I am getting a mail properly.

    But my requirement is to have the entire message in SQL like this - 

    And, when running the application, I need to read the string from sql and also substitute the actual values for entity.Price and entity.Product. I hope it is clear now and wanted to know if this is possible.

    The Product and Price value are not stored in the table. These values will be entered by the user during run time, which is why I chose to use entity.Product and entity.Price.



    Pauline Jeswin

    Friday, April 15, 2016 5:41 AM
  • Pauline, if I understand your requirements this is not about Lightswitch and you're trying to manage some string format templating?

    I don't know of any .NET oob solution, I think you'll have to perform some parsing of the template saved in you MailTable.

    There are some utilities around, maybe you could start from here:




    • Proposed as answer by Angie Xu Thursday, April 21, 2016 2:30 AM
    • Marked as answer by Angie Xu Thursday, April 28, 2016 8:38 AM
    Saturday, April 16, 2016 7:07 AM
  • I agree with Marco. Also, it looks like you may be sending a number of emails in that inserting method, which is probably not a good idea from an architectural perspective as you are keeping the LightSwitch database transaction open for the duration of sending all of those emails, so any delay name from the SMTP ever will further impact on this. I would create a temporary table for all outgoing emails, insert all the composed outgoing emails into that table and have a separate back ground process monitor that table and send out any pending emails. The background process can either be run as a Windows service or using the HangFire library - I think there is a post somewhere on the forum about using Hangfire with Lightswitch.

    Regards, Xander. My Blog

    Saturday, April 16, 2016 8:38 PM