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

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

Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?


From: Tom Roche
Subject: Re: extract smtpmail data from .authinfo (or .authinfo.gpg)?
Date: Fri, 26 Aug 2011 18:40:26 -0400
User-agent: GNU Emacs 23.3.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.4)

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>



reply via email to

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