Re: Sending emails through Microsoft 365

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Sending emails through Microsoft 365
De : alexandru.dadalau (at) *nospam* meshparts.de (alexandru)
Groupes : comp.lang.tcl
Date : 30. Nov 2024, 09:06:25
Autres entêtes
Organisation : novaBBS
Message-ID : <b81d266722c86c07561c006e76b710d5@www.novabbs.com>
References : 1
User-Agent : Rocksolid Light
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

Date Sujet#  Auteur
12 Nov 24 * Sending emails through Microsoft 3653Jonathan Kelly
23 Nov 24 +- Re: Sending emails through Microsoft 3651Ashok
30 Nov 24 `- Re: Sending emails through Microsoft 3651alexandru

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal