Link to home
Start Free TrialLog in
Avatar of anbu210
anbu210Flag for India

asked on

Send Email Functionality in Silverlight with body in HTML Format

I am using a Silverlight Application, Which contains several tab and each tab contains Datagrid.

 List<DataGrid> dtgrdCollection = new List<DataGrid>();
using above code + my additional functionality I have collected all datagrid as list array.

I have a Child window, which has few input fields like  Recipient's Email address, Subject line,  Personalized Message(body of email) and send Message,

I need a code snippet where I will pass my datagrid collection to SendEmail function in Childwindow...
and a SendEmail function which accepts input parameters and sends email to the recipient.

note that the Body of email should have all the datagrids values in a rows\column format one below the other with title header of each grids as datagrid.tag value.

Any help to start with would be appreciated.  Kindly help me..
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Get the xml from data grid and use XSLT to generate HTML file. Then use html file as the body for the mail message.

sample can be found here for xslt.
Avatar of anbu210

ASKER

@Gautham Janardhan....The code looks good....I am already using WCF RIA services in my Silverlight application. Should I need to create a new WCF service or include the code in same WCF RIA services..?

@apeter :  Link is not visible, could you re-post the sample ?
Avatar of Gautham Janardhan
Gautham Janardhan

you can use the same one
Avatar of anbu210

ASKER

Thanks Gautham ....I used in my Silverlight WCF RIA services and used onlinedomainContext to call it...
It worked with test email...

Now only pending item is how to generate html from the datagridcollection list and then pass it as body of message.

Any ideas on this ?
like apeter said you could generate the xml  and then use XSLT to generate HTML file.
Avatar of anbu210

ASKER

Finally it worked, I directly wrote a class file which takes input as Collection of Datagrid List and returns me string in HTML format (which contains data in table format) with some color, width formatting etc..

then I need to set as below, before setting body of the email....
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
Avatar of anbu210

ASKER

Send email functionality worked as mentioned in the link.
Avatar of anbu210

ASKER

@Gautham Janardhan,  It works fine when running in VS2012 or deploying in local machine IIS. However when deployed to test server (WIN server 2008 R2)  getting an exception "Unable to connect to remote server"

I have created new thread here : http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28475919.html

Please let me now if u have suggestions