unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jay Berkenbilt <ejb@ql.org>
To: help-gnu-emacs@gnu.org
Subject: using smtpmail to talk smtps over port 465: a workaround
Date: Wed, 19 Nov 2008 14:45:13 -0500	[thread overview]
Message-ID: <20081119144504.2680854345.qww314159@motoko.argon.local> (raw)


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 <ejb@ql.org>




                 reply	other threads:[~2008-11-19 19:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081119144504.2680854345.qww314159@motoko.argon.local \
    --to=ejb@ql.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).