For Programmers: Free Programming Magazines  


Home > Archive > Tcl > April 2005 > sending mail with binary attachments?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author sending mail with binary attachments?
Anchor

2005-04-24, 3:58 am

I am trying to do a mail out to membership list.

I have a cover letter and two attachments. The first is in word format
text document and the second is a png image.

I am using the dg_mail code from the wiki http://mini.net/tcl/1014.

I can send mail, I can send a text attachment, but I can not properly send
the cover letter with the pair of binary attachments.

The example works fine (sends a copy of the .tcl code as an attachment):

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

## example code works fine - send body with text attachment.
array set attcs_options {}
set attcs [file join [pwd] [info script]]

foreach attc $attcs {
## charset is optional
set opts [list -canonical "text/plain; charset=ascii; name=\"[file tail $attc]\""]
lappend opts -encoding quoted-printable
lappend opts -header {Content-Disposition attachment}
lappend opts -file $attc
set attcs_options($attc) $opts
}

dg_mail::sendmail sinisa@datagram.dg djoko2000@datagram.dg {Tcl smtp!} Hello! "" "" \
-file [namespace current]::attcs_options
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

When I try to send my binary attachments, the mail is sent but the
attachments are included in the text as binary gibberish. Clicking on the
attached file names in firefox, firefox complains that the attachments
are not in the correct format.

I suspect I need some more options set, but what options and what values?

Any thoughts?
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
#send mail attachment1 attachment1
set smtphost "..."
set from ...
set toList ...
set subject "..."
set body "..."
set header [list Date "[clock format [clock seconds]]"]
set bcc ""
set opt_attcs_type -file

set attc $attachment1 ;# word doc
array set attcs_options {}
set opts [list -canonical "text/doc; name=\"$attc\""]
#lappend opts -encoding binary ;# makes no difference
#lappend opts -header {Content-Disposition attachment} ;# makes no
difference
lappend opts -file [file join [pwd] $attc]
set attcs_options($attc) $opts

set attc $attachment2 ;# png image
array set attcs_options {}
set opts [list -canonical "image/png; name=\"$attc\""]
#lappend opts -encoding binary ;# makes no difference
#lappend opts -header {Content-Disposition attachment} ;# makes no
difference
lappend opts -file [file join [pwd] $attc]
set attcs_options($attc) $opts

# dg_mail::sendmail to from subject body {headers} {bcc} {opt__type} {attcs_array_name}

dg_mail::sendmail $toList $from $subject $body $header $bcc \
$opt_attcs_type [namespace current]::attcs_options

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

Anchor

2005-04-24, 8:57 pm

All fixed!


set smtphost "..."
set from "\"Membership Committee\" <membership@...>"
set toList "<...@...>"
set subject "docs attached"

set header [list Date "[clock format [clock seconds]]"]
set bcc ""

set attcs_type -file

set attc $attachment1 ;# word doc
array set attcs_options {}
set opts [list -canonical "application/octet-stream; name=\"[file tail $attc]\""]
lappend opts -header {Content-Disposition attachment}
lappend opts -file [file join [pwd] $attc]
set attcs_options($attc) $opts

set attc $attachment2 ;# png image
array set attcs_options {}
set opts [list -canonical "image/png; name=\"[file tail $attc]\""]
lappend opts -header {Content-Disposition attachment}
lappend opts -file [file join [pwd] $attc]
set attcs_options($attc) $opts

dg_mail::sendmail $toList $from $subject $body $header $bcc $attcs_type [namespace current]::attcs_options

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com