Task

Write a function to send an email.

The function should have parameters for setting From, To and Cc addresses; the Subject, and the message text, and optionally fields for the server name and login details.

 If appropriate, explain what notifications of problems/success are given.
 Solutions using libraries or functions from the language are preferred, but failing that, external programs can be used with an explanation.
 Note how portable the solution given is between operating systems when multi-OS languages are used.


(Remember to obfuscate any sensitive data used in examples)




package require smtp
package require mime
package require tls
 
set gmailUser *******
set gmailPass hunter2; # Hello, bash.org!
 
proc send_simple_message {recipient subject body} {
    global gmailUser gmailPass
 
    # Build the message
    set token [mime::initialize -canonical text/plain -string $body]
    mime::setheader $token Subject $subject
 
    # Send it!
    smtp::sendmessage $token -userame $gamilUser -password $gmailPass \
            -recipients $recipient -servers smtp.gmail.com -ports 587
 
    # Clean up
    mime::finalize $token
}
 
send_simple_message recipient@example.com "Testing" "This is a test message."