Discussion:
Sending emails through Microsoft 365
(too old to reply)
Jonathan Kelly
2024-11-12 20:01:12 UTC
Permalink
Hi,

our application currently sends out emails through our on-premise
exchange server using TCL. We're currently in the process of moving our
email to Microsoft 365, so has anyone managed to send email through M365
using TCL?

Jonathan.
Ashok
2024-11-23 03:13:52 UTC
Permalink
Perhaps Paul's CAWT Outlook module might help ?
https://www.tcl3d.org/cawt/download/CawtReference-Outlook.html
Post by Jonathan Kelly
Hi,
our application currently sends out emails through our on-premise
exchange server using TCL. We're currently in the process of moving our
email to Microsoft 365, so has anyone managed to send email through M365
using TCL?
Jonathan.
alexandru
2024-11-30 08:06:25 UTC
Permalink
If you have Outlook installed on the same machine that sends emails it
very easy with CAWT:

package require cawt
set appId [Outlook Open]
set mailTextId [Outlook CreateHtmlMail $appId [list $EMail] $subject
$body $attachmentList]
Outlook SendMail $mailTextId

You can also use pure Tcl to send mails directly through the mail
server.
This is my code, except for the true mail adress and password:

# This script sends a text/html formated email with a zip or pdf file
attached (optionally)

package require mime
package require smtp

set to [string trim [lindex $argv 0]]
set subject [lindex $argv 1]
set body [lindex $argv 2]
set attachment [lindex $argv 3]
set bcc [string trim [lindex $argv 4]]
set from [string trim [lindex $argv 5]]
set enc [string trim [lindex $argv 6]]
set pass [string trim [lindex $argv 7]]

if {$from==""} {
set from ***@domain.com
}
if {$enc==""} {
set enc cp1252
}
if {$pass==""} {
set pass yourpassword
}

proc sendmail {to subject body {attachment ""} {bcc {}} {from
***@domain.com} {enc cp1252} {pass ""}} {
set opts {}
lappend opts -servers [list smtp.office365.com]
lappend opts -ports [list 587]
lappend opts -usetls 1
lappend opts -username ***@domain.com
lappend opts -password yourpassword

lappend opts -header [list "Subject" [mime::word_encode $enc
quoted-printable $subject]]
lappend opts -header [list "From" $from]
lappend opts -header [list "To" $to]
if {[llength $bcc]} {
lappend opts -header [list "Bcc" $bcc]
}
# lappend opts -debug 1
if {$attachment==""} {
set mime_msg [mime::initialize -canonical "text/html" -param [list
charset $enc] -encoding "8bit" -string $body]
} else {
set apptype [string trim [file extension $attachment] .]
set mime_body [mime::initialize -canonical "text/html" -param
[list charset $enc] -encoding "8bit" -string $body]
set mime_zip [mime::initialize -canonical "application/$apptype;
name=\"[file tail $attachment]\"" -file $attachment]
set mime_msg [::mime::initialize -canonical "multipart/mixed"
-parts [concat $mime_body $mime_zip]]
}
smtp::sendmessage $mime_msg {*}$opts -queue false -atleastone false
-usetls true -debug 0
mime::finalize $mime_msg
}

sendmail $to $subject $body $attachment $bcc $from $enc $pass

Loading...