Forum OpenACS Q&A: Re: sending email with attachments

Collapse
Posted by Erik Rogneby on
If you are only going to be sending out one type of atachment and want a hard wired solution I used the following to generate a txt file attachment.

set set_id [ns_set new]
ns_set put $set_id "Mime-Version" "1.0"
ns_set put $set_id "Content-Type:" "text/plain; charset=\"us-ascii\""
ns_set put $set_id "Content-Disposition" "attachment; filename=\"$filename.txt\""
ns_sendmail $to $from $subject "$email_body" $set_id

For sending binary info just encoding the body and changing the Content-Type should do the trick. (although more mime info might be needed) I've decoded incoming attachment, but not the other way around. It turns out that text file attachments can be sent as actual text. (but don't have to be)

Anyhow, the fact that ns_sendmail can accept a set of mime information is what is really useful to communicate.

Hope this helps.