Hello guys,

I resolved my issue by setting the HOME env var at the beginning of the daemon
Thanks to David who gave me the correct way to set it with the python 
instruction:

os.environ['HOME'] = '/root'

instead of those I tried for doing the job:

os.system('set HOME=/root') or os.system('export HOME=/root')

I then do not need any .muttrc file

----- Mail original -----
> De: "Cameron Simpson" <[email protected]>
> À: "mathieu cier" <[email protected]>
> Cc: [email protected]
> Envoyé: Mardi 20 Octobre 2015 02:03:39
> Objet: Re: mutt returns a 256 error code
> 
> On 14Oct2015 14:44, [email protected] <[email protected]>
> wrote:
> >In fact, my problem comes from a strange way of linux startup [...]
> >I figured out that the daemon which is launched at boot as service
> >(stored in
> >/etc/rc2.d)
> >is executed as root but with a HOME=/ environment variable...
> >It seems that mutt tries to write content of mail in a sent file
> >which is located in this HOME folder
> >and it seems too it can't write in the / folder. When I restart my
> >daemon, the HOME env var is well
> >defined as /root folder and emails are sent correctly.
> 
> Personally, I tend to invoke sendmail directly and reply on the
> system's mail
> system. Assuming it is correctly set up, but that is worth doing
> anyway.

In fact I can't have sendmail installed on my embedded system
It is an ARM7 system with small amount of RAM and SD card filesystem
That's the mainly reason we not use sendmail have choosen mutt
 
> However, if you want "sent" copies etc then mutt is a convenient tool
> to make
> them.
> 
> >I tried to set/export the HOME var at beginning of the daemon code
> >but it still has the / value
> 
> That should work. Can you show us the code you used which did not
> worK?
> 
> >I then stored a .muttrc in / folder which is defining :
> >set record = '/root/sent'
> >and since, all is Ok but it is a solution I do not appreciate
> >because I have
> >to store the .muttrc file in
> >/, /root, ...
> 
> Yes, that is not pretty.
> 
> You can invoke mutt with -e options to issue commands, for example:
> 
>   mutt -e 'set record = "/root/sent"' ...
> 
> You can also tell it where the muttrc file is:
> 
>   mutt -F /root/.muttrc ...

Interesting. I keep the options in mind for future dev

Thanks to all

Mathieu

> 
> However, it might be best to set $HOME in your daemon startup script.
> 
> NB: replies to mutt-dev please, not to me personally.
> 
> Cheers,
> Cameron Simpson <[email protected]>
> 
> >Mathieu
> >
> >
> >
> >----- Mail original -----
> >De: "Cameron Simpson" <[email protected]>
> >À: "mathieu cier" <[email protected]>
> >Envoyé: Mercredi 14 Octobre 2015 13:17:57
> >Objet: Re: mutt returns a 256 error code
> >
> >On 14Oct2015 10:52, [email protected] <[email protected]>
> >wrote:
> >>Hi Cameron,
> >>Thanks for tip.
> >>I'll test it but quoting are ok since mutt can sometimes send mails
> >
> >Maybe the quoting isn't ok if it is only sometimes.
> >
> >By bypassing the shell (and thus quoting) entirely you get to avoid
> >all sorts
> >of issues that may come from eg quote characters in the message body
> >or
> >subject.
> >
> >If you're concerned, you could put some tracing in your shell
> >command, eg:
> >
> >  set -x; echo "body of the mail" | mutt -s "mail's subject"
> >  [email protected]
> >
> >assuming the output goes somewhere where it can be watched.
> >
> >Cheers,
> >Cameron Simpson <[email protected]>
> >
> >>Mathieu
> >>
> >>
> >>----- Mail original -----
> >>De: "Cameron Simpson" <[email protected]>
> >>À: "mathieu cier" <[email protected]>
> >>Cc: [email protected]
> >>Envoyé: Mercredi 14 Octobre 2015 00:17:41
> >>Objet: Re: Fwd: mutt returns a 256 error code
> >>
> >>On 13Oct2015 20:28, [email protected] <[email protected]>
> >>wrote:
> >>>I am currently using mutt 1.5.18 within a python script for
> >>>reporting some
> >>>activities about an embedded linux system.
> >>>I do not get any problem when launching the mutt command within a
> >>>terminal but I get troubles when launching from my python script.
> >>>
> >>>The command I use is pretty simple :
> >>>echo "body of the mail" | mutt -s "mail's subject"
> >>>[email protected]
> >>>
> >>>That command is called in the python script by:
> >>>retvalue = os.system(command)
> >>
> >>BTW, you might consider using subprocess:
> >>
> >>  from subprocess import Popen, PIPE
> >>
> >>  P = Popen(['mutt', '-s', mail_subject, target_address],
> >>  stdin=PIPE)
> >>  P.stdin.write(message_body)
> >>  P.stdin.close()
> >>  xit = P.wait()
> >>
> >>This avoids all sorts of nasty shell quoting issues that are
> >>inherent in your
> >>os.system() invocation.
> >>
> >>Cheers,
> >>Cameron Simpson <[email protected]>
> 

Reply via email to