Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: How to send mail by commandline

  1. #11
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to send mail by commandline

    To send mails from command-line the mail command alone is not enough. You also need a properly configured mail transfer agent (MTA). It doesn't have to be a full-fledged MTA like sendmail, postfix, or exim4. If all you want is getting mails off your system then you can use a simple relay-only MTA like ssmtp, esmtp, msmtp-mta, or nullmailer.

    Alternatively, use something like sendEmail or mentioned above mailsend instead of mail/mailx.

  2. #12
    Join Date
    Dec 2011
    Beans
    59

    Re: How to send mail by commandline

    Sorry, you are correct, I need to have the following command line to work properly- echo "mail body........" | mail -s "mail subject...." username@domain.com if required by destination mail server we can add the -aFrom:senderuser@localdomain too. the mail should go out of our local domain through ISP connection to any external mail address.

  3. #13
    Join Date
    Jan 2009
    Location
    ::1
    Beans
    2,460

    Re: How to send mail by commandline

    Quote Originally Posted by dvks View Post
    Sorry, you are correct, I need to have the following command line to work properly- echo "mail body........" | mail -s "mail subject...." username@domain.com if required by destination mail server we can add the -aFrom:senderuser@localdomain too. the mail should go out of our local domain through ISP connection to any external mail address.
    And why don't you use mailsend for that?

    No, let me rephrase that: what is your functional requirement?

    If your functional requirement is: "I want to send a mail from my system, with a certain from-address, with a certain (external) to-address, via a defined SMTP server, and possibly with an attachment" ... I would advice mailsend.

    If your functional requirement is "I want to use the 'mail' command line fuction", my question would be: Why?

  4. #14
    Join Date
    Dec 2011
    Beans
    59

    Re: How to send mail by commandline

    sanderj & schragge thanks for your time
    1. I need the "mail" to work since I need to resolve the send mail problem on a system that I am not too much familiar with and I know that they are using the "mail" command in their scripts, I prefer to fix mail instead of searching and changing the scripts.
    2. I understand from achragge that actually I will solve the problem by setting any MTA that can send mail, this is good.
    a. Can you recommend a "simple" MTA that can be used to send mail through ISP connection
    b. which of - ssmtp, esmtp, msmtp-mta, or nullmailer, or other should I choose, better one with good setting instructions.
    c. Any detailed instructions on setting of the MTA for sending out mail through ISP connection?
    Thanks

  5. #15
    Join Date
    Jan 2009
    Location
    ::1
    Beans
    2,460

    Re: How to send mail by commandline

    Quote Originally Posted by dvks View Post
    sanderj & schragge thanks for your time
    1. I need the "mail" to work since I need to resolve the send mail problem on a system that I am not too much familiar with and I know that they are using the "mail" command in their scripts, I prefer to fix mail instead of searching and changing the scripts.
    2. I understand from achragge that actually I will solve the problem by setting any MTA that can send mail, this is good.
    a. Can you recommend a "simple" MTA that can be used to send mail through ISP connection
    b. which of - ssmtp, esmtp, msmtp-mta, or nullmailer, or other should I choose, better one with good setting instructions.
    c. Any detailed instructions on setting of the MTA for sending out mail through ISP connection?
    Thanks
    I believe recommendations have already been given. Often there is wizard during the "sudo apt-get install". You should choose "smart host" and then select the local (or ISP) relay host.

    It was in the 90's that I did setup sendmail configs ... I'm so glad that I don't do that anymore ...

  6. #16
    Join Date
    Dec 2011
    Beans
    59

    Re: How to send mail by commandline

    I will try to set MTA and hope everything will start working.
    Appreciate you help
    Thanks

  7. #17
    Join Date
    Feb 2013
    Beans
    Hidden!

  8. #18
    Join Date
    Dec 2011
    Beans
    59

    Re: How to send mail by commandline

    schragge,
    Thanks for the information

  9. #19
    Join Date
    Jan 2009
    Location
    ::1
    Beans
    2,460

    Re: How to send mail by commandline

    OK ... I didn't want to do this, but I did:

    Setup Postfix:

    Code:
    sudo apt-get install postfix
    Fill out the wizard:
    - choose "Internet with smart host"
    - fill out FQDN of your host
    - fill out your (ISP's) smart host

    Ready

    Set hostname with a FQDN name:

    Code:
    sudo nano /etc/hostname
    Fill out a resolvable FQDN of your host. I choose a name of remote system / domain I own.
    Save and exit
    Reboot your system


    Install and use 'mail':

    Code:
    sudo apt-get install mailutils
    
    echo Hello | mail -s "this is a test" yourmailaddress@gmail.com

    ... and ... bingo! It works for me

    HTH

  10. #20
    Join Date
    Dec 2011
    Beans
    59

    Re: How to send mail by commandline

    Sanderj,
    Thanks for doing the extra steps and checking the setup
    I will follow your instructions
    Your feedback is very useful to me
    Thanks again

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •