ns_sendmail - Sending mail via SMTP
TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
COMMANDS
CONFIGURATION
ALTERNATIVES
EXAMPLES
SEE ALSO
KEYWORDS
|
ns_sendmail is a procedure for sending email from a Tcl script through a remote SMTP server. It now supports character encoding of subject and body, message-id creation, quoted printable text, AUTH PLAIN and LOGIN mechanisms. It is backwards compatible.
The helper command ns_sendmail_config returns or logs the current configuration for ns_sendmail.
In the default configuration mail is sent to "localhost" on port 25. Usually "localhost" resolves to the host where NaviServer is deployed and the running SMTP server accepts mail from the local machine.
In order to send mail directly to a specified SMTP server other than localhost some form of authentication may be required. The AUTH PLAIN and LOGIN mechanisms are supported as they are offered by most SMTP servers and easy to implement. Note, however, they are plaintext mechanisms and not secure. Also note that ns_sendmail does not verify if AUTH PLAIN or LOGIN are offered by the SMTP server at all. In case of an error the error code and message are returned.
Basic configuration options:
Extended configuration options:
Note: "boolean" in NaviServer configuration means value can be one of "true", "false", "on", "off", "0" or "1".
See the excellent TCL Standard Library smtp and mime packages.
Log current configuration to server log:
% ns_sendmail_config log
smtpconfiguration:
smtphost = mail.domain.tld
smtpport = 25
smtptimeout = 60
smtplogmode = false
smtpmsgid = on
smtpmsgidhostname = host.domain.tld
smtpencodingmode = on
smtpencoding = iso8859-15
smtpauthmode = PLAIN
smtpauthuser = account--0123
smtpauthpassword = mysecret
|
Default use:
% ns_sendmail to@example.com from@example.com "My subject" "My body" |
Separate multiple recipients with a comma (to,cc,bcc):
% ns_sendmail "to1@example.com,to2@example.com" \ from@example.com "My subject" "My body" |
You may give real names along with email address:
% ns_sendmail "Jo Foo <to1@example.com>,Pete Bar <to2@example.com>" \ from@example.com "My subject" "My body" |
For cc and bcc, leave header field empty, if you don't need it anyway:
% ns_sendmail "Jo Foo <to1@example.com>,Pete Bar <to2@example.com>" \ from@example.com "My subject" "My body" "" "Ben Care <bencare@example.com>" |
Header field is an ns_set array:
% set SMTP_setid [ns_set create SMTPHeaders "Reply-To" "marketing@example.com"] % ns_sendmail "Jo Foo <to1@example.com>,Pete Bar <to2@example.com>" \ from@example.com "My subject" "My body" $SMTP_setid \ "Ben Care <bencare@example.com>" |
Use smtplogmode to not send mail but watch transaction in server log:
% ns_sendmail "Mr. White <white@example.com>" "Mr. Black <black@example.com>" "log" "this message" Notice: S: Helo sock12 HELO devserver 60 Notice: S: Mail black@example.com sock12 MAIL FROM:<black@example.com> 60 Notice: S: Rcpt white@example.com sock12 RCPT TO:<white@example.com> 60 Notice: S: Data sock12 DATA 60 Notice: S: Data sock12 To: Mr. White <white@example.com> From: Mr. Black <black@example.com> Subject: log Date: Mon, 23 Jan 2006 09:25:22 GMT this message . 60 Notice: S: Quit sock12 QUIT 60 |
NaviServer , RFC2822 , mail , ns_sendmail , ns_sendmail_config , smtp