Executing /usr/bin/mail From Within Daemon

I've created a script that, among other things, sends an email to an external email address and it works fine from the command line.  When the same script is run periodically from within a daemon (i.e. launchctl), the email functionality of the script does not execute.  There are no errors in the system.log, the appfirewall.log or the mail.log.  All of my referenced paths are absolute.  I'm overlooking something, but don't know what.
Python:
cmd = "/bin/echo \"%s\" | /usr/bin/mail -s \"%s\" %s" % (messageText.strip(),subject,receiver)
os.system(cmd)
The question is, why does /usr/bin/mail not function correctly from within a daemon?
I appreciate your assistance

> Checked man mail but nothing that I could see...
That's because you're looking in the wrong place
mail uses your current login name combined with the domain settings for postfix, so it's postfix's configuration you need to be looking at.
Specifically:
/etc/postfix/main.cf
which states:
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.
So you should change the myorigin setting to reflect the @part of addresses for mail sent from this machine. It may be as simple as:
myorigin = $mydomain
if you just want to append your domain name.

Similar Messages

  • [SOLVED] Freezing while executing /usr/bin/openbox from Openbox menu

    I'm following the instructions in this webpage to create a dynamic menu. I have successfully achieved this on my laptop by installing the openbox-menu package and typing the following lines in menu.xml:
    <menu id="desktop-app-menu" label="Applications" execute="/usr/bin/openbox-menu lxde-applications.menu" />
    For some reason, the same doesn't work on my desktop PC. After editing and saving the menu.xml file, I restart Openbox and when I right click the desktop and hover the "Applications" menu item the desktop freezes. However, I can still move the mouse and switch to other ttys with Ctrl+Alt+Fx, therefore I believe it's reasonable to suggest that the problem lies in the permissions.
    What should I do about it?
    Last edited by Martificiam (2013-02-03 11:29:21)

    Umm, that's not "some random" webpage at all... It worked on all of my Arch Linux installations. The "lxde-applications.menu" is just an argument. But thanks for the link, I'll look into it.
    It's just that it's more of a workaround, not a solution, really... since it has ALWAYS worked for me.
    Furthermore, while setting up Arch on my laptop I remember experiencing similar problems (running a particular program from the openbox menu and resulting in a desktop freeze). This must have something to do with permissions.
    Edit: the xdg_menu worked perfectly, but I would still prefer to use the openbox-menu. I'm marking this as solved anyway.
    Last edited by Martificiam (2013-02-03 11:29:06)

  • /usr/bin/mail buggy or smtp server picky?

    I want to use mail to send email quickly from my terminal and decided to use msmtp as my smtp client to keep things light and straightforward.
    However, when I use /usr/bin/mail to send an email to [email protected], my smtp server (mail.messagingengine.com if you are interested) queues the email that was delivered by my /usr/bin/msmtp client fine (I get an OK for queue message), but after a couple of hours I get an NDR (Non Delivery Report) saying that my message couldn't be sent and will be retried until ultimately I get an NDR that my message couldn't be delivered.
    After some debugging, I realized that the reason the smtp server was having trouble is that my message didn't contain the From: header. Since the from address is already specified in the envelope upon SMTP-initiation, it seemed to me illogical that the smtp server couldn't just use that email.
    So I opened a ticket with those guys over at fastmail.fm, and they told me that the problem was not with the SMTP server, but with the mail client, which creates "invalid" messages (i.e. not sending the From: header). Since I trust my provider to know his stuff, here's my question:
    How can I tell /usr/bin/mail to insert a specific From: header?
    Thanks!

    Hello fukawi2,
    my ~/.mailrc contains one line:
    set sendmail=/usr/bin/msmtp
    Here's what happens when write an email using /usr/bin/mail from the mailx 8.1.1-7 package:
    [x@eee ~]$ mail [email protected]
    Subject: hello
    Another test
    EOT
    Here's how /usr/bin/mail passes my email to msmtp:
    /usr/bin/msmtp -i [email protected]
    To: [email protected]
    Subject: hello
    Another test
    Here's what my msmtp config looks like:
    #~/.msmtp
    account fastmail
    from "[email protected]"
    host mail.messagingengine.com
    auth on
    tls on
    tls_certcheck off
    user [email protected]
    password "*"
    logfile ~/msmtp.log
    Here's what the msmtp log shows when I send the email:
    nov 18 00:28:41 host=mail.messagingengine.com tls=on auth=on user=[email protected] from=[email protected] recipients=[email protected] mailsize=41 smtpstatus=250 smtpmsg='250 2.0.0 Ok: queued as C3A00A7B7' exitcode=EX_OK
    I will send the NDR from the SMTP server when it arrives (takes a couple of hours) if you'd like to inspect it.
    Maybe ssmtp has a way to insert a From: header automatically, I haven't taken a look at it. Maybe even msmtp has a way to do that, even though I haven't found that option in the man pages.
    What I am trying to say is, if the /usr/bin/mail program cannot be configured to create a valid rfc-compliant email, then using an intermediary mail transport agent like ssmtp would only be a workaround but not a permanent fix. Hence my suggestion to replace mailx with a compliant, working package in the arch core install.
    Any ideas on how to proceed from here?
    Last edited by awayand (2009-11-17 23:37:45)

  • Using /usr/bin/mail

    I have some Perl scripts in which I would like to utilize /usr/bin/mail to send e-mail. I've tried using /usr/bin/mail from the command line to send a test message to my yahoo address, and it fails. I imagine this is pretty basic stuff for a Unix sysadmin, but all I've ever been is a user. What do I need to do to use /usr/bin/mail to send mail?
    Thanks,
    Brad

    the main thing you need is an open port 25. If it's open, then command line mail should work out of the box with no further preparation. it works on my work computer for example and I can send mail to my yahoo address from it.
    However, most internet providers block port 25. I suspect that's the case for you. then you need to set up mail to work with some external smtp server. I've never done it but it should be possible. see these links
    http://www.macosxhints.com/article.php?story=20081217161612647
    http://www.macosxhints.com/article.php?story=20050911184730802

  • How to execute a packaged function from within DML

    Hi
    can someone explain in how many ways can we execute a packaged function from within a DML statement.
    examples will help.
    Thanks

    Hi,
    There's no difference between using functions in DML and using functions in any other SQL statement. Almost any place where a literal is allowed, you can have any kind of expression, including a an expression involving one or more functions.
    For example, in
    UPDATE  table_x
    SET     column_a = 0
    WHERE   column_b > SYSDATE;You could use functions instead of 0, column_b, or SYSDATE. (Actually, SYSDATE is a function.) You can not use functions instead of table_x or column_a (since it is to the left of the "=" sign).

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • Problem sending mail from within C#

    Sorry, I am posting this question for the second time !!!!
    I have constructed a snippet that sends mail from within C#.In My script, there are will be several receivers of my mail. The script will read from a file, mail addresses and send mail to each individual contained in the file. As test I run the script with
    two mail addresses in the file,one my own and the second with outlook mail. However, the result is I get the mail but the second receiver  never gets it.
       What is the problem ????
    Please help
    I debugged the program and verified that Nsmtp and Mailreceiver are correct
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Net.Mime;
    using System.Text;
    using System.Windows.Forms;
    namespace Note_Pss
    public partial class Email : Form
    public Note_Pss.Form1 m_parent;
    Util util = new Util(); string signal = "#";
    char g = System.Convert.ToChar("*");
    char X = System.Convert.ToChar("@");
    Utility_Types utility_type = new Utility_Types(); string P = "";
    char p; String Mailsender; String Npass; String Nsmtp;
    String Mailreceiver; String Mailbody; String MailTitle;
    MailMessage mail = new MailMessage();
    public Email(Note_Pss.Form1 parent)
    InitializeComponent();
    m_parent = parent;
    string ListContent = util.openf(wsk.storagedbase + @"\TemFile");
    wsk.listArray = util.arrayadjust(ListContent, signal);
    private void multi_mail_Send()
    {char g = System.Convert.ToChar("*");
    MailParameters();
    int Count_num = wsk.listArray.Count;
    for (int i = 0; i < Count_num; i++)
    string P = wsk.listArray[i].ToString();
    string[] Sub_File = P.Split(g);
    Mailreceiver = Sub_File[2].ToString();
    Nsmtp = "smtp."+msmtp_name(Mailreceiver, "@");
    Send_Mail();
    //if (Enclosure.Text != "") MailAttachment();
    //MailBody();
    private String msmtp_name(string p, string p_2)
    string P = p.ToString();
    string[] Pp = P.Split(X);
    string bbb = Pp[1];
    return bbb;
    private void MailParameters()
    Mailsender = Sender.Text;
    Npass = Senderpass.Text;
    Mailbody = Body.Text;
    MailTitle = Subject.Text;
    private void Send_Mail()
    try
    MailMessage mail = new MailMessage();
    SmtpClient client = new SmtpClient();
    client.Port = 587;
    client.Host = Nsmtp;
    mail.From = new MailAddress(Mailsender);
    mail.To.Add(Mailreceiver);
    mail.Subject = MailTitle;
    mail.Body = Mailbody;
    textBox1.Text = Nsmtp + " " + Mailreceiver;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential(Mailsender, Npass);
    client.EnableSsl = true;
    client.Send(mail);
    catch (Exception ex) { textBox1.Text = ex.ToString(); }
    private void MailSend_Click(object sender, EventArgs e)
    { multi_mail_Send(); }
    private void button2_Click(object sender, EventArgs e)
    { Enclosure.Text = util.openImage();}
    private void button1_Click(object sender, EventArgs e)
    this.Close();

    Nsmtp and Mailreceiver are verified through debugging:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net.Mail;
    using System.Net.Mime;
    using System.Net;
    namespace Note_Pss
    public partial class Email : Form
    public Note_Pss.Form1 m_parent;
    Util util = new Util(); string signal = "#";
    char g = System.Convert.ToChar("*");
    char X = System.Convert.ToChar("@");
    Utility_Types utility_type = new Utility_Types(); string P = "";
    char p; String Mailsender; String Npass; String Nsmtp;
    String Mailreceiver; String Mailbody; String MailTitle;
    MailMessage mail = new MailMessage();
    public Email(Note_Pss.Form1 parent)
    InitializeComponent();
    m_parent = parent;
    string ListContent = util.openf(wsk.storagedbase + @"\TemFile");
    wsk.listArray = util.arrayadjust(ListContent, signal);
    private void multi_mail_Send()
    char g = System.Convert.ToChar("*");
    MailParameters();
    int Count_num = wsk.listArray.Count;
    for (int i = 0; i < Count_num; i++)
    string P = wsk.listArray[i].ToString();
    string[] Sub_File = P.Split(g);
    Mailreceiver = Sub_File[2].ToString();
    Nsmtp = "smtp." + msmtp_name(Mailreceiver, "@");
    Send_Mail();
    //if (Enclosure.Text != "") MailAttachment();
    //MailBody();
    private String msmtp_name(string p, string p_2)
    string P = p.ToString();
    string[] Pp = P.Split(X);
    string bbb = Pp[1];
    return bbb;
    private void MailParameters()
    Mailsender = Sender.Text;
    Npass = Senderpass.Text;
    Mailbody = Body.Text;
    MailTitle = Subject.Text;
    private void Send_Mail()
    try
    MailMessage mail = new MailMessage();
    SmtpClient client = new SmtpClient();
    client.Port = 587;
    client.Host = Nsmtp;
    mail.From = new MailAddress(Mailsender);
    mail.To.Add(Mailreceiver);
    mail.Subject = MailTitle;
    mail.Body = Mailbody;
    //SmtpServer.Port = 25;
    //textBox1.Text = Nsmtp + " " + Mailreceiver;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential(Mailsender, Npass);
    client.EnableSsl = true;
    client.Send(mail);
    // MessageBox.Show("mail Send");
    catch (Exception ex) { }
    private void MailSend_Click(object sender, EventArgs e)
    { multi_mail_Send(); }
    private void button2_Click(object sender, EventArgs e)
    { Enclosure.Text = util.openImage(); }
    private void button1_Click(object sender, EventArgs e)
    this.Close();

  • Dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

    After upgrading to ML, I am now getting this message when I try to sudo.  I've repaired permissions, rebuilt the dyld cache, and removed the DYLD_LIBRARY_PATH environment variable, all with no success.  Met with this message each time:
    $ sudo ls
    dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
    Password:
    Any help is appreciated.
    Thanks!

    In short, I find this solution:
         comment out `export LD_LIBRARY_PATH=XXX` in .bash_profile
    I do not have DYLD_LIBRARY_PATH in bash env

  • Executing a perl script from within java application

    Hi,
    Does anyone knows a way to execute a perl script from within java.
    ---kirk

    Runtime.exec("perl myscript.pl");
    Of course whether that "works" depends on what the script does and where the java program runs.

  • Executing a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?

    don't crosspost.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100

  • [SOLVED] /usr/bin/echo from systemd .service

    I use systemd to execute a shell script to change the status of an LED after boot when I reach multi-user state.  It is working fine, but I wanted to execute the shell script lines from within my systemd .service file instead of the systemd .service file executing the shell script.  Below is the systemd .service file but it’s not working.  The systemctl status shows no issues, but I have a gut feeling my problem might be related to me redirecting the /usr/bin/echo to a device. Could someone lend a suggestion?
    Description=Set Green LED
    After=multi-user.target
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/echo none > /sys/class/leds/status\:blue\:health/trigger
    ExecStart=/usr/bin/sleep 1
    ExecStart=/usr/bin/echo default-on > /sys/class/leds/status\:green\:health/trigger
    [Install]
    WantedBy=multi-user.target
    Here is my systemctl status output:
    setgreenled.service - Set Green LED
       Loaded: loaded (/etc/systemd/system/setgreenled.service; enabled)
       Active: inactive (dead) since Tue 2013-06-04 14:12:52 PDT; 3s ago
      Process: 273 ExecStart=/usr/bin/echo default-on > /sys/class/leds/status\:green\:health/trigger (code=exited, status=0/SUCCESS)
      Process: 270 ExecStart=/usr/bin/sleep 1 (code=exited, status=0/SUCCESS)
      Process: 268 ExecStart=/usr/bin/echo none > /sys/class/leds/status\:blue\:health/trigger (code=exited, status=0/SUCCESS)
    Jun 04 14:12:51 pogoplug systemd[1]: Starting Set Green LED...
    Jun 04 14:12:52 pogoplug echo[273]: default-on > /sys/class/leds/status\:green\:health/trigger
    Jun 04 14:12:52 pogoplug systemd[1]: Started Set Green LED.
    If I execute the lines below from the command-line it works fine.
    /usr/bin/echo none > /sys/class/leds/status\:blue\:health/trigger
    /usr/bin/echo default-on > /sys/class/leds/status\:green\:health/trigger
    If I put the commands into a shell script and use systemd .service to execute the shell script, it works fine.  Here is that .service script
    [Unit]
    Description=Set Green LED
    After=multi-user.target
    [Service]
    Type=simple
    ExecStart=/usr/bin/sh /home/public/setgreenled.sh
    [Install]
    WantedBy=multi-user.target
    Last edited by calzon65 (2013-06-05 00:55:37)

    Systemd services are not shells.  So redirects will not work in that way.  You can use "bash -c '<command here>'" to accomplish this as that will create a shell for the command to run.  But I think that berbae is right that there are better alternatives for this.
    You can use tmpfiles (man tmpfiles.d) which you can use to simply write a value to the given path, or you can use a udev rule to run a command when that particular path is detected.  Beware though that for some things, the tmpfiles way will sometimes try to run itself before the actual creation of the directory.  So you may run into some pace conditions with that method.  For some things, it is totally reliable though... so you'll just have to test and see.
    A tmpfiles.d configuration is way easier to write than a udev rule.  But what you are trying to do would be a pretty basic udev rule, so it would probably not take you very long to learn how to do it.  It simply involves learning how to use the udevadm command really.

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • Attaching pictures to Mail from within iPhoto

    For my sister in law I am trying to find out, why she cannot attach photos to mails anymore, i.e. from within iPhoto. In iPhoto, when you select one or more photos, then click on Mail on icon list below the photos, the photos are prepared for attachment. In a pop-up window you can choose from different sizes, for example. When you click on ok, a progress bar appears. Once the process is complete nothing happens, Mail does not open. Also, there is no draft mail created in Mail. What went wrong? How do I fix it? Attaching photos by dragging them on the Mail icon in the dock works fine, though. Thanks a lot in advance.

    Given that iPhoto goes through the motions of resizing etc, I would suspect the problem is at the Mail end.
    Has she tried repairing permissions with Disk Utility?

  • Executing a Java Program from within a Java Program

    I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
    D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
    I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.

    Assuming your code didn't get mangled by the forum
    (it's missing one "), it may be that your "-cp
    E:\\Develop.." argument is getting quoted as it has a
    space in it; try passing "-cp" and "E:\\Develop..."
    as two arguments.That worked; specifically the following tested OK:
    ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
    pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
    try{
         Process p = pb.start();
         InputStream is = p.getErrorStream();
         InputStreamReader isr = new InputStreamReader(is);
         BufferedReader br = new BufferedReader(isr);
         String line;
         while ((line = br.readLine()) != null)
              System.out.println(line);
         p.waitFor();
    }catch(IOException ioe){
    I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine.

  • Executing an HTML file from within Java

    My program produces a file of run statistics formatted as html (stats.htm).
    I want to execute this file in a browser from within my program - ie. call a browser with this file as a parm.
    How do I do that ?
    Have tried executing a DOS command for the form "cmd /C fullpathname-of-file" but it does nothung.
    Thanks
    ...KenR

    Thank you very much...that worked file.
    The relevant code is:
    String arg = "G:/tma03/agents/stats.htm";
    java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); ...to set-up Desktop object
    try ... to create a URI object using arg
    java.net.URI uri = new java.net.URI( arg );
    desktop.browse( uri ); ... to browse the URI
    }

Maybe you are looking for