Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send multiple attachments with cfmail...?

Status
Not open for further replies.

jianhua

Programmer
Jun 22, 2001
55
US
I have a project to send mass email. The problem is how to send multiple attachments with this mass email. Any suggestions...?

jianhua
 
Prior to ColdFusion 4.5 there was no simple way to send multiple e-mail attachments using the <CFMAIL> tag. In CF 4.5 that tags MIMEATTACH attribute still only supports a single attachment, but you can use multiple <CFMAILPARAM> tags to attach multiple attachments. - tleish
 
Thanks, tleish.

If I use form <input type=&quot;file&quot; name=&quot;attachment&quot;> to browse the files, do I have to have several <input>, for example:
<input type=&quot;file&quot; name=&quot;attachment1&quot;>
<input type=&quot;file&quot; name=&quot;attachment2&quot;>
...
and then use same number of <cfmailparam>?

Is there any way I can use a list with the delimiter &quot;;&quot; to do it as I did for the email list...? (<cfmail to=&quot;#ValueList(queryname.email, &quot;;&quot;)#&quot;...>) or loop...?

Thanks again,
jianhua
 
You should be able to code an interface in javascript that lets the user repeat this multiple times: browse for a file, add it to a list (a list kept in a Javascript variable). When the user submits, the list can be appended to the URL of the new page or serialized into a WDDX packet and passed to the new page. I would recommend against using semicolon as a delimiter as it's a valid character in a filename. Use a tab or something. We usually use a chr(6).
 
Thanks, a440guy.
Do you have any sample code or code similiar to that javascript part as I'm not good at javascript?
 
The following works in IE 5.5. It does not work in Netscape 4.7 because Netscape is not capturing the event &quot;onChange&quot;. If your users use Netscape, you'll have to experiment to find out which events are being captured. Or try Netscape 6.2

Also, there are other ways to get the Javascript data to ColdFusion.

<cfparam name=&quot;operation&quot; default=&quot;get files&quot;>
<cfif operation=&quot;get files&quot;>
<script language=&quot;javascript&quot;>
var fileList = '';

function appendToList(s) {
var delim = ','; //assumes that there are no commas in the filename or path

if (fileList.length == 0) {
delim = '';
}
fileList = fileList + delim + s;
}

function assign_filelist(f) {
f.filespeclist.value = fileList;
return true;
}

</script>

<form name=&quot;getfiles&quot; onSubmit=&quot;return assign_filelist(this);&quot; method=&quot;post&quot;>
<input type=&quot;file&quot; name=&quot;filespec&quot; onChange=&quot;appendToList(this.value);&quot;><br>
<input type=&quot;hidden&quot; name=&quot;filespeclist&quot; value=&quot;&quot;>
<input type=&quot;hidden&quot; name=&quot;operation&quot; value=&quot;process&quot;><br>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>

</form>

<cfelse>
<cfoutput><br>#filespeclist#</cfoutput>

</cfif>
 
Thank you very much, a440guy. I'll try that...
 
You will probably want to give the user the opportunity to edit the list too. What if they select the wrong file? There is no way for them to remove it from the list, except by refreshing the page and starting over. We have used a TEXTAREA to display the list elements, one per line. The javascript puts the filename selected into the TEXTAREA as they are selected (instead of filespeclist above) and the user can edit the TEXTAREA directly. When processing the TEXTAREA variable, you must remember that the list delimiter will be a newline.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top