CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 Emailing a document

Print topic Send  topic

Author Message
Benjamin Krajmalnik
Posted: 02/16/2006, 11:23 AM

I just implemented built-in e-mail capabilities into my applications.
It was quite straight forward.
The imlpementation is in ASP, but PHP could be done just as easily.

I created one page, which is my "e-mail client". It gets passed 2
parameters, the document type and the document number.
The AfterPageInitialize event is used to pull some information from the
source document (such as the account number related to the source document)
so I can populate the available "to" addresses - implemented in a
multi-check list.
The from address is a text field, which is automatically primed with the
logged-in user's e-mail address.
I added a freeform "to: text field to send to additional persons not in the
list of account e-mail addresses, as well as a cc and additional messge text
boxes.

Now, the trick to the entire framework lies in the following. I have a
label field (html) which dynamically creates an iframe calling the actual
CCS page we want to e-mail, with an additional parameter (email=1). On the
unload event, I save the contents of the page to a session variable. When I
submit the page, I call a wrapper function which I created which puts all of
the pieces together, sends the email, clears the session variable containing
the e-mail content, and spools javascript to close the window.

As I mentioned, the code is in ASP, but easily ported to any other language.
If anyone is interested I will see how I can post the source in this forum.


Stephan Kastner
Posted: 02/20/2006, 1:39 AM

Hi Benjamin

I am interested in seeing your code.
Please populate it or give us a link to download.

Thanks
Stephan
Benjamin Krajmalnik
Posted: 02/24/2006, 10:09 AM

Stephan,

I am in the midst of a major release of our products.
As soon as that is fdone, I will post something.

Benjamin Krajmalnik
Posted: 02/27/2006, 3:38 PM

Here it goes:

HTML File:

<html>
<head>
<title>Email Documents</title>
<link rel="stylesheet" type="text/css" href="{Theme}/Style.css">
<script language="JavaScript" type="text/javascript">
//Begin CCS script
//Include JSFunctions @1-11DC2871
</script>
<script language="JavaScript" type="text/javascript"
src="functions.js"></script>
<script language="JavaScript" type="text/javascript">

//End Include JSFunctions

//page_OnLoad @1-D0F4E1D3
function page_OnLoad()
{
var result;
//End page_OnLoad

//Custom Code @263-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
setupAllTabs;
//End Custom Code

//Close page_OnLoad @1-BC33A33A
return result;
}
//End Close page_OnLoad

//bind_events @1-B716D3FC
function bind_events() {
page_OnLoad();
forms_onload();
}
//End bind_events

window.onload = bind_events; //Assign bind_events @1-19F7B649

//End CCS script
</script>
<body>
<table cellspacing="1" cellpadding="3" border="0">
<tr>
<td>

<!-- BEGIN Record email -->
<form name="{HTMLFormName}" action="{Action}" method="post">
<font class="FormHeaderFont"></font>
<table class="FormTABLE" cellspacing="2" cellpadding="3"
border="0">
<!-- BEGIN Error -->
<tr>
<td class="ErrorDataTD" colspan="2">{Error}</td>
</tr>
<!-- END Error -->
<tr>
<td class="FieldCaptionTD" nowrap>From:</td>
<td class="DataTD"><input class="Input" value="{Sender}"
name="{Sender_Name}" maxlength="80" size="80"></td>
</tr>

<tr>
<td class="FieldCaptionTD" nowrap>To:</td>
<td class="DataTD"
width="500"><b>{defaultrecipient}</b>  (default recipient unless
unchecked in the listbox below)<hr>
<div style="FLOAT: left; OVERFLOW: auto; WIDTH: 450px;
HEIGHT: 60px; BACKGROUND-COLOR: #ffffff">
<!-- BEGIN CheckBoxList Recipient --><span
style="width:210px;"><input type="checkbox" name="{Recipient_Name}"
value="{Value}" {Check}>{Description}</span>
<!-- END CheckBoxList Recipient -->
</div>
<input name="{AddTo_Name}" value="{AddTo}" class="Input" size="80"></td>
</tr>

<tr>
<td class="FieldCaptionTD" nowrap>cc:</td>
<td class="DataTD"><input class="Input" value="{cc}"
name="{cc_Name}" size="80"></td>
</tr>

<tr>
<td class="FieldCaptionTD" nowrap>bcc:</td>
<td class="DataTD"><input class="Input" value="{bcc}"
name="{bcc_Name}" size="80"></td>
</tr>

<tr>
<td class="FieldCaptionTD" nowrap>Subject:</td>
<td class="DataTD"><input class="Input" value="{Subject}"
name="{Subject_Name}" maxlength="120" size="80"></td>
</tr>

<tr>
<td class="FieldCaptionTD" nowrap>Message:</td>
<td class="DataTD"><textarea class="AquaTextarea"
name="{messagetext_Name}" rows="5" cols="50">{messagetext}</textarea></td>
</tr>

<tr>
<td class="FooterTD" nowrap align="right" colspan="2">
<!-- BEGIN Button Button_Insert --><input class="Button"
type="submit" value="Send" name="{Button_Name}"><!-- END Button
Button_Insert --> <input class="Button" id="Cancel"
onclick="window.close()" type="button" value="Cancel" name="Cancel"></td>
</tr>

</table>

</form>
<!-- END Record email -->
<hr>{edoc}
</td>
</tr>
</table>
</body>
</html>

Note the {edoc} towards the end of the HTML. This will generate a dynamic
iframe based on some parameters passed to the procedure.

Function edoc_BeforeShow() 'edoc_BeforeShow @278-E5737577

'Custom Code @279-73254650
' -------------------------
' Write your own code here.
' -------------------------
Dim URL
select case DocType
case "Invoice"
URL = "<IFRAME
src=""InvoicesPrint.asp?InvoiceNumber="&DocNumber&"&email=1"" height=800
width=720 height=40 scrolling=""yes"" frameborder=""0""></IFRAME> "
case "SO"
URL = "<IFRAME
src=""ServiceOrdersPrint.asp?SONumber="&DocNumber&"&email=1"" height=800
width=720 height=40 scrolling=""yes"" frameborder=""0""></IFRAME> "
case "Quote"
URL = "<IFRAME src=""QuotesPrint.asp?QuoteNumber="&DocNumber&"&email=1""
height=800 width=720 height=40 scrolling=""yes""
frameborder=""0""></IFRAME> "
case else
URL = ""
end select
EventCaller.Value = URL

'End Custom Code

End Function 'Close edoc_BeforeShow @278-54C34B28

The main oricedure gets passed a document type and document number,
The function above dynamicaly generates the correc URL to "embed" the HTML.
Not the email=1 parameter tuple.
The actual document which is uncluded checks for this parameter. If the
parameter is set, it saves the generated HTML to a session variable.

Now, for the mailing portion I wrote a simple wrapper around CDOSys.

Dim MyRecipients

MyRecipients = Request.Form("Recipient")
if email.addto.value <> "" then
MyRecipients = MyRecipients & "; " & email.addto.value
end if
MyRecipients = Replace(MyRecipients, ",", ";")
email.cc.value = Replace(email.cc.value, ",", ";")
if email.cc.value = "" then
email.cc.value = email.sender.value
else
email.cc.value = email.sender.value & "; " & email.cc.value
end if
email.bcc.value = Replace(email.bcc.value, ",", ";")

' send the email

ilSendMail email.sender.value, MyRecipients, email.cc.value,
email.bcc.value, email.Subject.Value, email.messagetext.value,
Session("emailcontent")

That's pretty much it.

brucewin

Posts: 143
Posted: 04/13/2006, 3:53 PM

That sounds cool, how can I do it in PHP?
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.