Knowledge Base: Generating e-mails in ASP.NET

B

Blue Streak

Hello,

I am trying to develop an interface to view an internal knowledge base. One feature I would like to add is a "Generate E-Mail" button which would automatically open an e-mail message a populate it with the title and the article from the knowledge base. Each KBase item contains a title and article where the article contains HTML formatting. So far, I have used a client-side JavaScript block to perform this task along with an HTML control.

i.e.
<INPUT onclick=GenerateEMail() type=button value="Generate E-mail" name=btnEmail />
....
function GenerateEMail()
{
oDiv = document.all.pnlArticle;
oDiv.contentEditable = 'true';
if (oDiv.innerHTML != '')
{
subject = escape(document.frmKBase.lstTitle.options[document.frmKBase.lstTitle.selectedIndex].text);
var controlRange;
if (document.body.createControlRange)
{
controlRange = document.body.createControlRange();
controlRange.addElement(oDiv);
controlRange.execCommand('Copy');
oWin = window.open('mailto:[email protected]?subject='+ subject);
}
oDiv.contentEditable = 'false';
}
else
{
alert('Please select an article!');
}

I use the copy command to the clipboard so that the HTML formatting is not lost. The problem with this method is that you need to perform a paste when the e-mail message window opens up.

Is there a way to have the article pasted automatically?

Is there a way of doing this all in ASP.NET?

TIA...
 
M

Matt Berther

Hello Blue,

Try something (code from memory, so it may not be perfect) like this hooked
up to a button:

string html = "";

using (StringWriter sw = new StringWriter())
{
Html32TextWriter hw = new Html32TextWriter(sw);
pnlArticle.RenderControl(hw);
hw.Close();
html = sw.ToString();
}

At this point, you have an HTML representation of the content in the pnlArticle
panel. Look at System.Web.Mail [1] for information on how to send the email.
You'll want to make sure to set the MailFormat property.


[1] http://www.systemwebmail.net
 
B

Blue Streak

Thank you much!


Matt Berther said:
Hello Blue,

Try something (code from memory, so it may not be perfect) like this hooked
up to a button:

string html = "";

using (StringWriter sw = new StringWriter())
{
Html32TextWriter hw = new Html32TextWriter(sw);
pnlArticle.RenderControl(hw);
hw.Close();
html = sw.ToString();
}

At this point, you have an HTML representation of the content in the pnlArticle
panel. Look at System.Web.Mail [1] for information on how to send the email.
You'll want to make sure to set the MailFormat property.


[1] http://www.systemwebmail.net

--
Matt Berther
http://www.mattberther.com
Hello,

I am trying to develop an interface to view an internal knowledge
base. One feature I would like to add is a "Generate E-Mail" button
which would automatically open an e-mail message a populate it with
the
title and the article from the knowledge base. Each KBase item
contains a title and article where the article contains HTML
formatting.
So far, I have used a client-side JavaScript block to perform this
task
along with an HTML control.
i.e.
<INPUT onclick=GenerateEMail() type=button value="Generate E-mail"
name=btnEmail />
...
function GenerateEMail()
{
oDiv = document.all.pnlArticle;
oDiv.contentEditable = 'true';
if (oDiv.innerHTML != '')
{
subject =
escape(document.frmKBase.lstTitle.options[document.frmKBase.lstTitle.s
ele
ctedIndex].text);
var controlRange;
if (document.body.createControlRange)
{
controlRange = document.body.createControlRange();
controlRange.addElement(oDiv);
controlRange.execCommand('Copy');
oWin = window.open('mailto:[email protected]?subject='+
subject);
}
oDiv.contentEditable = 'false';
}
else
{
alert('Please select an article!');
}
I use the copy command to the clipboard so that the HTML formatting is
not lost. The problem with this method is that you need to perform a
paste when the e-mail message window opens up.

Is there a way to have the article pasted automatically?

Is there a way of doing this all in ASP.NET?

TIA...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top