From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jay Berkenbilt Newsgroups: gmane.emacs.help Subject: using smtpmail to talk smtps over port 465: a workaround Date: Wed, 19 Nov 2008 14:45:13 -0500 Message-ID: <20081119144504.2680854345.qww314159@motoko.argon.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227125685 30493 80.91.229.12 (19 Nov 2008 20:14:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Nov 2008 20:14:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 19 21:15:49 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L2tSl-0004D9-IX for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Nov 2008 21:15:47 +0100 Original-Received: from localhost ([127.0.0.1]:56825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L2tRc-00014R-HN for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Nov 2008 15:14:36 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L2szK-00023M-BM for help-gnu-emacs@gnu.org; Wed, 19 Nov 2008 14:45:22 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L2szJ-000239-Pk for help-gnu-emacs@gnu.org; Wed, 19 Nov 2008 14:45:22 -0500 Original-Received: from [199.232.76.173] (port=34482 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L2szJ-000232-HC for help-gnu-emacs@gnu.org; Wed, 19 Nov 2008 14:45:21 -0500 Original-Received: from hermes.mail.tigertech.net ([64.62.209.72]:55254) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L2szJ-0002iN-6v for help-gnu-emacs@gnu.org; Wed, 19 Nov 2008 14:45:21 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by hermes.tigertech.net (Postfix) with ESMTP id DC43C4303D7; Wed, 19 Nov 2008 11:45:15 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at hermes.tigertech.net Original-Received: from motoko.argon.local (unknown [72.165.80.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by hermes.tigertech.net (Postfix) with ESMTP id 068CD4303E9; Wed, 19 Nov 2008 11:45:14 -0800 (PST) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Wed, 19 Nov 2008 15:13:29 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:59938 Archived-At: I was looking for a way to use smtpmail to communicate to a mail server using smtps, port 465, on a connection on which TLS has been established before EHLO. This is as opposed to using STARTTLS on a normal SMTP connection after EHLO, which is already supported by smtpmail. In my search for information, I came across this thread: http://thread.gmane.org/gmane.emacs.help/52049 I implemented a relatively simple workaround that gives me the functionality I'm looking for, since in this case, I have no choice but to use port 465 if I want to talk to this mail server. My "solution" to this problem was to wrap my call to smtpmail-send-it in an flet that redirects open-network-stream to open-tls-stream and does some cleanup of the buffer. It's a little bit of a brute force solution, but hopefully it might be useful to someone who may come across this message while searching for an answer. (defun smtps-smtpmail-send-it () (let* ((smtpmail-smtp-server "smtps.example.com") (smtpmail-smtp-service 465) (user-mail-address "username@example.com") (smtps-login "username") (smtps-mail-password "password") (smtpmail-auth-credentials `((,smtpmail-smtp-server ,smtpmail-smtp-service ,smtps-login ,smtps-mail-password)) ) ) (require 'tls) (flet ((open-network-stream (name buffer host service) (progn (let ((process (open-tls-stream name buffer host service))) (with-current-buffer (process-buffer process) (goto-char (point-min)) ;; gnutls-cli puts text in the process buffer that ;; confuses smtpmail-read-response, so delete ;; everything up to what looks like an SMTP ;; response. (if (re-search-forward "^[0-9][0-9][0-9] " nil t) (delete-region (point-min) (match-beginning 0)) ) ) process ) ) ) ) (smtpmail-send-it) ) ) ) I hope this is useful to someone. (I'm not subscribed to the list. I'm not looking for a reply, but if you reply, please CC me. Thanks.) -- Jay Berkenbilt