• Sending emails through Microsoft 365

    From Jonathan Kelly@21:1/5 to All on Wed Nov 13 07:01:12 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ashok@21:1/5 to Jonathan Kelly on Fri Nov 22 22:13:52 2024
    Perhaps Paul's CAWT Outlook module might help ? https://www.tcl3d.org/cawt/download/CawtReference-Outlook.html

    On 11/12/2024 3:01 PM, Jonathan Kelly wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From alexandru@21:1/5 to All on Sat Nov 30 08:06:25 2024
    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 default@domain.com
    }
    if {$enc==""} {
    set enc cp1252
    }
    if {$pass==""} {
    set pass yourpassword
    }

    proc sendmail {to subject body {attachment ""} {bcc {}} {from default@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 default@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)