[comp.emacs] making GNU Emacs talk SMTP

rsm@amethyst.ma.arizona.edu (Robert Maier) (03/06/89)

It would be nice if GNU Emacs, when used as a mail user agent, would
send mail by talking SMTP to a mail server instead of just invoking a
local `sendmail'.

Has anyone succeeded in making Emacs talk SMTP?  Coding in Elisp beats
writing a sendmail.cf any day...

--
Robert S. Maier
INTERNET: rsm@amethyst.ma.arizona.edu
SNAIL: Dept. of Math.; Univ. of Arizona; Tucson, AZ 85721; USA
PSTN: +1 602 621 6893 / +1 602 621 2617		BITNET: maier@arizrvax
UUCP: ..{allegra,cmcl2,hao!noao}!arizona!amethyst!rsm

bard@THEORY.LCS.MIT.EDU (03/06/89)

> It would be nice if GNU Emacs, when used as a mail user agent, would
> send mail by talking SMTP to a mail server instead of just invoking a
> local `sendmail'.

Why?  (Intended as a question rather than a flame.)  

One advantage of the sendmail approach is that it is fairly asynchronous.
(Actually, I haven't looked at the code so this is just a guess.)  Emacs can
give the letter to sendmail and then forget about it.  The sendmail runs in
parallel, sending the letter to all the 82 people I've mailed my letter to; I
can continue to edit my thesis without waiting for the letter to get
delivered.  If it were all done in emacs (which is a synchronous critter in
general), I'd have to wait.

-- Bard the emacs gargoyle

lear@NET.BIO.NET (Eliot Lear) (03/06/89)

No offense, but doesn't emacs do enough?  To implement a mailer you
really must have some sort of queuing structure, because nothing ever
goes right with mail (or so it should be presumed).  And then the
queue must be run, and cleaned, etc.  If you like, I can send you a
sendmail.cf tutorial that was posted to the net some years ago.

Eliot
-- 
Eliot Lear
[lear@net.bio.net]

bob@tinman.cis.ohio-state.edu (Bob Sutterfield) (03/06/89)

Similar things have been suggested wrt having GNUS whisper NNTP in the
ears of more than one NNTP server at posting time.  The objective in
this case was more immediate dispersal of a news article, rather than
ease of configuration.

I think both schemes of using Emacs as a message delivery agent
constitute layering violations.  Both solve problems in ways that
would be unique to users of GNU Emacs, but don't offer any benefits to
users of other interfaces (mh, elm, rn, gnews) to the same transport.

However, this would be a good evangelistic tool... :-)

simmons@nucst4.neep.wisc.EDU (03/07/89)

I am interested in a sendmail tutorial. Please email me at
                     simmons@nucst4.neep.wisc.edu
                                                    Thanx.....

pinkas@hobbit.intel.com (Israel Pinkas ~) (03/07/89)

In article <RSM.89Mar5162359@onyx.ma.arizona.edu> rsm@amethyst.ma.arizona.edu (Robert Maier) writes:

> It would be nice if GNU Emacs, when used as a mail user agent, would
> send mail by talking SMTP to a mail server instead of just invoking a
> local `sendmail'.
>
> Has anyone succeeded in making Emacs talk SMTP?  Coding in Elisp beats
> writing a sendmail.cf any day...

I have to disagree.  There are a number of problems with this.

1) GNU Emacs runs on many machines that don't have SMTP, or that don't use
SMTP for mail delivery.  There are sites that use POP, uucp, and other
mailer configurations.

2) You would still have to write the sendmail.cf.  Look at MH (the Rand
Mailer).  The default configuration is to connect to the SMTP server.
(Normally this is localhost, but you might want all mail to be delivered to
one machine.)  Since the SMTP server is usually sendmail, you wind up
writing the sendmail.cf.

3) Most mailers deliver mail by invoking sendmail with flags.  There may be
a reason for a site to replace sendmail with a program that does something
site-specific.  For example, sites that use NFS without lockd might want to
force all mail to the server machine.

It would not be difficult to write an SMTP package in Elisp (see the NNTP
package in GNUS).  I just think that it is unnecessary.

Besides, you could always use the MH-E package that is supplied.  This does
almost exactly what you want.

-Israel
--
--------------------------------------
Disclaimer: The above are my personal opinions, and in no way represent
the opinions of Intel Corporation.  In no way should the above be taken
to be a statement of Intel.

UUCP:	{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!cadev4!pinkas
ARPA:	pinkas%cadev4.intel.com@relay.cs.net
CSNET:	pinkas@cadev4.intel.com

cudcv@warwick.ac.uk (Rob McMahon) (03/18/89)

In article <PINKAS.89Mar6124251@hobbit.intel.com> pinkas@hobbit.intel.com (Israel Pinkas ~) writes:
|In article <RSM.89Mar5162359@onyx.ma.arizona.edu> rsm@amethyst.ma.arizona.edu (Robert Maier) writes:
|
|> It would be nice if GNU Emacs, when used as a mail user agent, would send
|> mail by talking SMTP to a mail server instead of just invoking a local
|> `sendmail'.
|>
|> Has anyone succeeded in making Emacs talk SMTP?  Coding in Elisp beats
|> writing a sendmail.cf any day...
|
|I have to disagree.  There are a number of problems with this.
|
|1) GNU Emacs runs on many machines that don't have SMTP
|2) You would still have to write the sendmail.cf.
|3) Most mailers deliver mail by invoking sendmail with flags

It would still be useful if gnumacs could talk SMTP to the local sendmail
daemon, rather than starting up a new copy of sendmail, even if it did no
routing decisions.  Once the sendmail.cf files is written it's done, and
there's no point in writing another version in Elisp, but at least this would
save the overhead of starting a new sendmail process for each mail item.

Rob
-- 
UUCP:   ...!mcvax!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv@uk.ac.warwick             ARPA:   cudcv@warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England

rlk@think.com (Robert Krawitz) (03/20/89)

In article <121@titania.warwick.ac.uk>, cudcv@warwick (Rob McMahon) writes:
]It would still be useful if gnumacs could talk SMTP to the local sendmail
]daemon, rather than starting up a new copy of sendmail, even if it did no
]routing decisions.

When you connect to sendmail via smtp over the network, the master
sendmail daemon forks a new copy.  The process creation still takes
place.
-- 
ames >>>>>>>>>  |	Robert Krawitz <rlk@think.com>	245 First St.
bloom-beacon >  |think!rlk	(postmaster)		Cambridge, MA  02142
harvard >>>>>>  .	Thinking Machines Corp.		(617)876-1111

shirono@hcx3.SSD.HARRIS.COM (03/24/89)

*> comp.emacs  cudcv@warwick.ac.uk  Mar 17, 1989 <*
> It would still be useful if gnumacs could talk SMTP to the local sendmail
> daemon, rather than starting up a new copy of sendmail, even if it did no
> routing decisions.  Once the sendmail.cf files is written it's done, and
> there's no point in writing another version in Elisp, but at least this would
> save the overhead of starting a new sendmail process for each mail item.

I think I would agree with this, if not necessarily for the same reasons.  I
have no problems with starting up a new sendmail process every time I want
to send mail (you still would have to start up a telnet process to talk to
the smtp service).

My particular problem is that I have recently encountered a system where the
"-t" option of sendmail ("read recipients from message") is restricted to
the superuser.  This results in a message without recipients, which results
in the following message:

	 554 shirono... Recipient names must be specified

This problem has three possible solutions that I see (there may be more, and
I have no idea which will be more useful/efficient)
	- Teach sendmail.el to parse the message better and use the proper
	  command-line options in invoking sendmail.
	- Write a C program to go in ${EMACS}/etc to send the message (much
	  like movemail), parsing it appropriately and invoking an
	  appropriate service.
	- Teach sendmail.el how to talk SMTP.
	- Rewrite sendmail.el to use some other mail agent (/bin/mail,
	  /usr/bin/mail).

wjc@ho5cad.ATT.COM (Bill Carpenter) (03/27/89)

In article <94600020@hcx3> shirono@hcx3.SSD.HARRIS.COM writes:
>My particular problem is that I have recently encountered a system where the
>"-t" option of sendmail ("read recipients from message") is restricted to
>...
>	- Write a C program to go in ${EMACS}/etc to send the message (much
>	  like movemail), parsing it appropriately and invoking an
>	  appropriate service.
>	- Rewrite sendmail.el to use some other mail agent (/bin/mail,

*Poof*  You dreams can come true.  There is already etc/fakemail which
is used by sites that don't have sendmail (and for those like me who
choose to ignore it).  Out of the box, it gathers up addresses from
the "TO:", "CC:", and "BCC:" lines, drops the "BCC:" from the message,
and pipes into /bin/mail.

A couple months back, I posted some diffs to make etc/fakemail also
drop (comments) from the address list, linewrap the embedded address
lists, and let you optionally pipe into something other than
/bin/mail.  If you missed the posted diffs and would like them, send
me some mail.

(I concur with the idea that this kind of jazz ought to be done in the
elips and get rid of etc/fakemail, but it was easier for me to write
30 lines in C than 200 lines in elisp.)

While we're on the subject of sending mail, here is something I use to
get my failed mail in a real buffer instead of just crammed into the
minibuffer:

;;----------------  badmailbuf.el
;; swiped from sendmail-send-it in sendmail.el by att!ho5cad!wjc
;; 
;; The difference is that this one plops its stuff into a buffer
;; instead of the minibuffer if mail fails
;;
(defun badmailbuf:sendmail-send-it ()
  (let ((errbuf (if mail-interactive
		    (get-buffer-create "*mail errors*")
		  0))
	(tembuf (generate-new-buffer " sendmail temp"))
	(case-fold-search nil)
	delimline
	(mailbuf (current-buffer)))
    (unwind-protect
	(save-excursion
	  (set-buffer tembuf)
	  (erase-buffer)
	  (insert-buffer-substring mailbuf)
	  (goto-char (point-max))
	  ;; require one newline at the end.
	  (or (= (preceding-char) ?\n)
	      (insert ?\n))
	  ;; Change header-delimiter to be what sendmail expects.
	  (goto-char (point-min))
	  (re-search-forward
	    (concat "^" (regexp-quote mail-header-separator) "\n"))
	  (replace-match "\n")
	  (backward-char 1)
	  (setq delimline (point-marker))
	  (if mail-aliases
	      (expand-mail-aliases (point-min) delimline))
	  (goto-char (point-min))
	  ;; ignore any blank lines in the header
	  (while (and (re-search-forward "\n\n\n*" delimline t)
		      (< (point) delimline))
	    (replace-match "\n"))
	  (let ((case-fold-search t))
	    ;; Find and handle any FCC fields.
	    (goto-char (point-min))
	    (if (re-search-forward "^FCC:" delimline t)
		(mail-do-fcc delimline))
	    ;; If there is a From and no Sender, put it a Sender.
	    (goto-char (point-min))
	    (and (re-search-forward "^From:"  delimline t)
		 (not (save-excursion
			(goto-char (point-min))
			(re-search-forward "^Sender:" delimline t)))
		 (progn
		   (forward-line 1)
		   (insert "Sender: " (user-login-name) "\n")))
	    ;; don't send out a blank subject line
	    (goto-char (point-min))
	    (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
		(replace-match ""))
	    (if mail-interactive
		(save-excursion
		  (set-buffer errbuf)
		  (erase-buffer))))
	  (apply 'call-process-region
		 (append (list (point-min) (point-max)
			       (if (boundp 'sendmail-program)
				   sendmail-program
				 "/usr/lib/sendmail")
			       nil errbuf nil
			       "-oi" "-t")
			 ;; Don't say "from root" if running under su.
			 (and (equal (user-real-login-name) "root")
			      (list "-f" (user-login-name)))
			 ;; These mean "report errors by mail"
			 ;; and "deliver in background".
			 (if (null mail-interactive) '("-oem" "-odb"))))

		)
	  )
	(kill-buffer tembuf)
	(if mail-interactive
		(progn (set-buffer errbuf)
			   (if (zerop (buffer-size))
				   (kill-buffer errbuf)
				 (display-buffer errbuf)
				 (error "Sending...failed")
				 )
			   (set-buffer mailbuf)
			   )
	  )))

; From wjc Sun Jan  1 22:11 EST 1989
; To:...
; Subject: bad mail buffer
; Reply-to: att!ho5cad!wjc
; 
; I have found a way to make failed mail come back to a regular buffer
; (instead of the minibuffer) so that you can see the whole deal.  You
; should just have to do this someplace:
; 
; (setq mail-interactive t)
; (setq send-mail-function 'badmailbuf:sendmail-send-it)
; (autoload 'badmailbuf:sendmail-send-it "badmailbuf")
; (setenv "FAKEMAILER" "/bin/mail") ;; optional ... can leave it unset
; 
; Let me know if you try this and it doesn't work right.
; --
;    Bill Carpenter         att!ho5cad!wjc  or  attmail!bill
; 
--
--
   Bill Carpenter         att!ho5cad!wjc  or  attmail!bill