help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using smtpmail to talk smtps over port 465: a workaround


From: Jay Berkenbilt
Subject: using smtpmail to talk smtps over port 465: a workaround
Date: Wed, 19 Nov 2008 14:45:13 -0500

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 via email to

[Prev in Thread] Current Thread [Next in Thread]