* extract smtpmail data from .authinfo (or .authinfo.gpg)?
@ 2011-08-17 0:56 Tom Roche
2011-08-17 3:37 ` Vijay Lakshminarayanan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tom Roche @ 2011-08-17 0:56 UTC (permalink / raw)
To: help-gnu-emacs
summary: To send email, I currently use smtpmail and .authinfo: the
latter doesn't store any passwords, but does have hostname, id, and
port. The latter are duplicated in an elisp file I load from my init.el.
I'd prefer to have the latter use, or read the data from, .authinfo:
how to do?
details:
I'm using
GNU Emacs 23.3.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.4)
of 2011-04-10 on brahms, modified by Debian
on
$ lsb_release -ds
Linux Mint Debian Edition
$ uname -rv
2.6.39-2-amd64 #1 SMP Tue Jul 5 02:51:22 UTC 2011
I send email using plain smtpmail configured by a file name=tlrMail.el
which I load from init.el. Among other things (like
(require 'smtpmail)
) tlrMail loads some SMTP info, e.g.,
(setq foo-smtp-server-port 26)
(setq foo-smtp-server-hostname "smtp.foo.com")
(setq foo-user-mail-id "me")
(setq foo-starttls-credentials
(list (list foo-smtp-server-hostname foo-smtp-server-port 'nil 'nil)))
where "foo" is like a profile name in some email clients. This works,
but it duplicates data that's also in my .authinfo (e.g.,
machine smtp.foo.com login me port 26
). Is there a way I can make my elisp use .authinfo directly, or scrape
the relevant data from .authinfo? Or better yet, from .authinfo.gpg?
(And I'd appreciate pointers to tutorials regarding use of
.authinfo.gpg, and GPG with smtpmail generally.)
Feel free to reply directly to me as well as the list.
Your suggestions are appreciated, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
2011-08-17 0:56 extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
@ 2011-08-17 3:37 ` Vijay Lakshminarayanan
2011-08-17 16:21 ` problem using .authinfo.gpg with smtpmail Tom Roche
2011-08-17 16:47 ` extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2 siblings, 0 replies; 7+ messages in thread
From: Vijay Lakshminarayanan @ 2011-08-17 3:37 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Tom Roche
Tom Roche <Tom_Roche@pobox.com> writes:
> ). Is there a way I can make my elisp use .authinfo directly, or scrape
> the relevant data from .authinfo? Or better yet, from .authinfo.gpg?
> (And I'd appreciate pointers to tutorials regarding use of
> .authinfo.gpg, and GPG with smtpmail generally.)
As long as you have gnupg in your PATH, things should generally Just
Work. Open your .authinfo, C-x w .authinfo.gpg and Emacs will ask you
for a password for the file. And then you're done.
--
Cheers
~vijay
Gnus should be more complicated.
^ permalink raw reply [flat|nested] 7+ messages in thread
* problem using .authinfo.gpg with smtpmail
2011-08-17 0:56 extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2011-08-17 3:37 ` Vijay Lakshminarayanan
@ 2011-08-17 16:21 ` Tom Roche
2011-08-17 16:47 ` extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2 siblings, 0 replies; 7+ messages in thread
From: Tom Roche @ 2011-08-17 16:21 UTC (permalink / raw)
To: help-gnu-emacs
summary: I believe I am properly configured to use .authinfo.gpg with
sendmail.el. However, when I try to send mail, I get the usual messages,
followed by 2 requests for passphrase, followed by failure:
> (error "Sending failed; SMTP protocol error")
I also observe a problem reading .authinfo.gpg from emacs (details
below), though it looks fine in bash. How to fix?
details:
Vijay Lakshminarayanan Wed, 17 Aug 2011 09:07:05 +0530
> As long as you have gnupg in your PATH,
Just for the benefit of the next literal-minded newbie:
me@it:~$ which gnupg
# `C-h i`, then
me@it:~$ which gpg
/usr/bin/gpg
me@it:~$ gpg --version
gpg (GnuPG) 1.4.11
I also have
me@it:~$ lsb_release -ds
Linux Mint Debian Edition
me@it:~$ uname -rv
2.6.39-2-amd64 #1 SMP Tue Jul 5 02:51:22 UTC 2011
me@it:~$ emacs --version
GNU Emacs 23.3.1
init.el
> (if (>= emacs-major-version 23)
> (progn
> (require 'auth-source)
> (if (file-exists-p "~/.authinfo.gpg")
> (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t)))
> (setq auth-sources '((:source "~/.authinfo" :host t :protocol t)))
> )
> )
> )
...
> (load "tlrMail")
tlrMail.el
> (setq user-full-name "Tom Roche")
> (setq message-send-mail-function 'smtpmail-send-it)
> ;;; throw this in, anyway
> (setq send-mail-function 'smtpmail-send-it)
modified for mail (works in original)
> (setq foo-smtp-server-port 26)
> (setq foo-smtp-server-hostname "smtp.foo.com")
> (setq foo-user-mail-id "me")
> (setq foo-starttls-credentials
> (list (list foo-smtp-server-hostname foo-smtp-server-port 'nil 'nil)))
...
> (setq smtpmail-local-domain pobox-domain-name)
> (setq smtpmail-sendto-domain pobox-domain-name)
> (setq smtpmail-smtp-server pobox-smtp-server-hostname)
> (setq smtpmail-smtp-service pobox-smtp-server-port)
> (setq user-mail-address pobox-user-mail-address)
> (setq smtpmail-starttls-credentials pobox-starttls-credentials)
...
> (setq starttls-use-gnutls t)
> (setq starttls-gnutls-program "gnutls-cli")
> (setq starttls-extra-arguments nil)
> (require 'smtpmail)
Vijay Lakshminarayanan Wed, 17 Aug 2011 09:07:05 +0530
> Open your .authinfo, C-x w .authinfo.gpg and Emacs will ask you for a
> password for the file.
So I did
1 C-x f ~/.authinfo
2 C-x w ~/.authinfo.gpg
and got dialog=*Keys*
> Select recipents for encryption.
> If no one is selected, symmetric encryption will be performed.
> - `m' to mark a key on the line
> - `u' to unmark a key on the line
> [Cancel][OK]
3 OK, then got 2 GnuPG passphrase prompts. I set a passphrase different
from my SMTP server passwords.
4 I sent email, which succeeded normally, i.e., emacs prompted me for
the SMTP server password, but I did not get a GnuPG prompt for passphrase.
5 rm ~/.authinfo
6 I tried to send email, but failed with
*Backtrace*
> Debugger entered--Lisp error: (error "Sending failed; SMTP protocol error")
7 Just to be sure, I did `C-x f ~/.authinfo.gpg` and got the GnuPG
passphrase prompt followed by seeing the correct file contents in
buffer.
8 Confused, I restarted emacs (normally), then tried to send email, I
* loaded the *Mail* buffer
* `C-c C-c`
* got 2 GnuPG passphrase prompts (why 2?)
* failed with
*Backtrace*
> Debugger entered--Lisp error: (error "Sending failed; SMTP protocol error")
9 More confused, I restarted the OS, then repeated the previous step: no change.
10 `C-x f ~/.authinfo.gpg` gets GnuPG passphrase prompt, followed by
*Messages*
> File exists, but cannot be read
But I was able to open it before restarting emacs and the OS! Furthermore
me@it:~$ ls -al .authinfo.gpg
-rw-r--r-- 1 me me 183 Aug 17 10:29 .authinfo.gpg
11 .authinfo.gpg -> .authinfo
*`C-x f ~/.authinfo~`
* restore old contents
* `C-x w ~/.authinfo`
* `chmod 600 ~/.authinfo`
* verify:
me@it:~$ ls -al ~/.authinfo.gpg
ls: cannot access /home/me/.authinfo.gpg: No such file or directory
me@it:~$ ls -al ~/.authinfo
-rw------- 1 me me 260 Aug 17 11:56 /home/me/.authinfo
* try resending message (without restarting emacs): success!
How to fix (or further debug)?
Feel free to reply directly to me as well as the list, and TIA, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
2011-08-17 0:56 extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2011-08-17 3:37 ` Vijay Lakshminarayanan
2011-08-17 16:21 ` problem using .authinfo.gpg with smtpmail Tom Roche
@ 2011-08-17 16:47 ` Tom Roche
2011-08-17 18:03 ` Ian Zimmerman
2011-08-26 22:40 ` Tom Roche
2 siblings, 2 replies; 7+ messages in thread
From: Tom Roche @ 2011-08-17 16:47 UTC (permalink / raw)
To: help-gnu-emacs
Tom Roche Tue, 16 Aug 2011 20:56:18 -0400
>> I currently use smtpmail and .authinfo: the latter doesn't store any
>> passwords, but does have hostname, id, and port. The latter are
>> duplicated in an elisp file I load from my init.el. I'd prefer to
>> have the latter use, or read the data from, .authinfo [or
>> .authinfo.gpg:] how to do?
Vijay Lakshminarayanan Wed, 17 Aug 2011 09:07:05 +0530
> As long as you have [gpg] in your PATH, things should generally Just
> Work. Open your .authinfo, C-x w .authinfo.gpg and Emacs will ask you
> for a password for the file.
That part works, but
* smtpmail is choking on the .authinfo.gpg interaction: details @
https://lists.gnu.org/archive/html/help-gnu-emacs/2011-08/msg00116.html
* using .authinfo.gpg doesn't address the topic, which is how to prevent
the data duplication. Does smtpmail have some mechanism to extract
server name, port#, etc from .authinfo*. Alternatively, how to elisp
read-and-extract? (Unfortunately my elisp is pretty weak, so any
assistance is appreciated.)
Feel free to reply directly to me as well as the list, and TIA, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
2011-08-17 16:47 ` extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
@ 2011-08-17 18:03 ` Ian Zimmerman
2011-08-26 22:40 ` Tom Roche
1 sibling, 0 replies; 7+ messages in thread
From: Ian Zimmerman @ 2011-08-17 18:03 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Tom Roche
Tom> * using .authinfo.gpg doesn't address the topic, which is how to
Tom> prevent the data duplication. Does smtpmail have some mechanism to
Tom> extract server name, port#, etc from .authinfo*. Alternatively, how
Tom> to elisp read-and-extract? (Unfortunately my elisp is pretty weak,
Tom> so any assistance is appreciated.)
I don't understand; that is what smtpmail does by default. Are you sure
you even tried it?
Here's my .authinfo, massaged for public consumption:
machine my.linode.server login itz password s3kri7 port 993
machine my.linode.server login itz password s3kri7 port 587
(587 is the SMTP port on the server).
--
Ian Zimmerman
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD
Rule 420: All persons more than eight miles high to leave the court.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
2011-08-17 16:47 ` extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2011-08-17 18:03 ` Ian Zimmerman
@ 2011-08-26 22:40 ` Tom Roche
2011-09-07 0:33 ` Ian Zimmerman
1 sibling, 1 reply; 7+ messages in thread
From: Tom Roche @ 2011-08-26 22:40 UTC (permalink / raw)
To: help-gnu-emacs
Tom Roche Wed, Aug 17, 2011 at 12:47 PM
>> * Does smtpmail have some mechanism to extract server name, port#,
>> etc from .authinfo*. Alternatively, how to elisp read-and-extract?
pcode like
get_connection_data(filename=~/.authinfo, servername)
connection_string=line containing servername in filename
from connection_string, parse pairs for machine, login, port, etc
return pairs except for machine (which we already know)
>> (Unfortunately my elisp is pretty weak, so any assistance is
>> appreciated.)
Ian Zimmerman Wed, 17 Aug 2011 11:03:36 -0700
> I don't understand; that is what smtpmail does by default.
Not mine--more below.
> Here's my .authinfo, massaged for public consumption:
> machine my.linode.server login itz password s3kri7 port 993
> machine my.linode.server login itz password s3kri7 port 587
That's very similar to mine, but I don't currently have passwords in
massaged .authinfo
> machine smtp.foo.com login me port 26
> machine smtp.bar.com login me port 587
So I don't think the problem is in my .authinfo, but in my code (or
smtpmail.el, but I guess bugs in that would've been caught already).
myMail.el gets called from my init.el:
massaged working myMail.el
+ ;;; mail-related elisp------------------------------------------------
+ (setq user-full-name "Me Me Me")
+ (setq message-send-mail-function 'smtpmail-send-it)
+ ;;; throw this in, anyway
+ (setq send-mail-function 'smtpmail-send-it)
+ ;;; debugging==t
+ (setq smtpmail-debug-info t) ; only this is necessary?
+ (setq smtpmail-debug-verb t)
+ (setq smtpmail-auth-credentials (expand-file-name "~/.authinfo"))
+ ; following could all be gotten from ~/.authinfo? or ~/.authinfo.gpg?
+ ;;; using foo.com---------------------------------------------------
+ (setq foo-smtp-server-port 26) ; evil blocks 25
+ (setq foo-domain-name "foo.com")
+ (setq foo-smtp-server-hostname "smtp.foo.com")
+ (setq foo-user-mail-id "me")
+ (setq foo-user-mail-name "Me_Me")
+ (setq foo-user-mail-address (concat foo-user-mail-name "@" foo-domain-name))
+ (setq foo-starttls-credentials
+ (list (list foo-smtp-server-hostname foo-smtp-server-port 'nil 'nil) ))
+ ;;; using bar.com------------------------------------------------
+ (setq bar-domain-name "bar.com")
+ (setq bar-smtp-server-hostname "smtp.bar.com")
+ (setq bar-smtp-server-port 587)
+ (setq bar-user-mail-id "me")
+ (setq bar-user-mail-address (concat bar-user-mail-id "@" bar-domain-name))
+ (setq bar-starttls-credentials
+ (list (list bar-smtp-server-hostname bar-smtp-server-port 'nil 'nil) ))
+ ;;; using whatever----------------------------------------------------
+ ;;; s/foo/bar/g or vv
+ (setq smtpmail-local-domain foo-domain-name)
+ (setq smtpmail-sendto-domain foo-domain-name)
+ (setq smtpmail-smtp-server foo-smtp-server-hostname)
+ (setq smtpmail-smtp-service foo-smtp-server-port)
+ (setq user-mail-id foo-user-mail-id)
+ (setq user-mail-address foo-user-mail-address)
+ ;;; TLS---------------------------------------------------------------
+ (setq starttls-use-gnutls t)
+ (setq starttls-gnutls-program "gnutls-cli")
+ (setq starttls-extra-arguments nil)
+ ;;; load libraries----------------------------------------------------
+ ;; after setting variables above
+ (require 'smtpmail)
+ ;; (require 'starttls) ; apparently unnecessary
This works (i.e., mail gets sent), except that
- I'm explicitly setting connection data ('user-mail-id',
'smtpmail-smtp-service'), which I would like to lookup from
.authinfo (given 'smtpmail-smtp-server' as "primary key")
- I can only switch between SMTP servers by editing myMail.el and
byte-compile-file, but that's the topic of another thread (namely
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-08/msg00111.html
)
So what happens if I comment-out the other data? With my .authinfo unchanged, and
me@it:~$ diff -u ~/.emacs.d/myMail.el_good ~/.emacs.d/myMail.el
...
-(setq smtpmail-smtp-service pobox-smtp-server-port)
-(setq user-mail-id pobox-user-mail-id)
+; (setq smtpmail-smtp-service pobox-smtp-server-port)
+; (setq user-mail-id pobox-user-mail-id)
after I
- `M-x byte-compile-file ~/.emacs.d/myMail.el`
- restart emacs
- try to send mail
I get
*Backtrace*
> Debugger entered--Lisp error: (error "Sending failed; SMTP protocol error")
> signal(error ("Sending failed; SMTP protocol error"))
> error("Sending failed; SMTP protocol error")
> smtpmail-send-it()
> message-send-mail(nil)
> message-send-via-mail(nil)
> message-send(nil)
> message-send-and-exit(nil)
> call-interactively(message-send-and-exit nil nil)
and no mail. But if I
+ `cp ~/.emacs.d/myMail.el_good ~/.emacs.d/myMail.el`
+ `M-x byte-compile-file ~/.emacs.d/myMail.el`
+ restart emacs
I can again send mail. So my question is, how to get my code to read the port and id from .authinfo, given the hostname?
TIA, Tom Roche <Tom_Roche@pobox.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
2011-08-26 22:40 ` Tom Roche
@ 2011-09-07 0:33 ` Ian Zimmerman
0 siblings, 0 replies; 7+ messages in thread
From: Ian Zimmerman @ 2011-09-07 0:33 UTC (permalink / raw)
To: help-gnu-emacs
Tom> I can again send mail. So my question is, how to get my code to
Tom> read the port and id from .authinfo, given the hostname?
What is the value of smtpmail-auth-credentials ?
--
Ian Zimmerman
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD
Rule 420: All persons more than eight miles high to leave the court.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-09-07 0:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-17 0:56 extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2011-08-17 3:37 ` Vijay Lakshminarayanan
2011-08-17 16:21 ` problem using .authinfo.gpg with smtpmail Tom Roche
2011-08-17 16:47 ` extract smtpmail data from .authinfo (or .authinfo.gpg)? Tom Roche
2011-08-17 18:03 ` Ian Zimmerman
2011-08-26 22:40 ` Tom Roche
2011-09-07 0:33 ` Ian Zimmerman
[not found] <87d3frx23d.fsf@pobox.com>
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).