unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* using smtpmail to talk smtps over port 465: a workaround
@ 2008-11-19 19:45 Jay Berkenbilt
  0 siblings, 0 replies; only message in thread
From: Jay Berkenbilt @ 2008-11-19 19:45 UTC (permalink / raw)
  To: help-gnu-emacs


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>




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-19 19:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19 19:45 using smtpmail to talk smtps over port 465: a workaround Jay Berkenbilt

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).