cat - file.log << EOF | sendmail -t to:recipient@somewhere.com from:you@yourdomain.com subject:Testing 123 EOF ================ You should be able to read in a file like the following into "sendmail -t" Code: to:recipient@somewhere.com from:you@yourdomain.com subject:Testing 123 This is my message. ================ I am trying to figure out how I can append a subject to sendmail from the command line. I am using RH Enterprise. using bash shell sendmail -f"from name" "recipient" <"file" that sends the mail but no subject. I have tried this as well mail -s"Subject header" "recipient" <"file" But that will not allow me to change the from address. It send it saying root, when I am trying to mask that. any suggestions would be greatly appreciated. ============================ [Log in to get rid of this advertisement] I need help with commandline sendmail. I want to send an email with an attachment . I would like to be able to use the Cc: and Bcc: Subject: Body: plus have an attachement sent with the email. !cat /tmp/testpage.txt | /usr/sbin/sendmail -i -oi -f "from@from.com" "sendto@sendto.com" this places the file into the body, but the format gets messed up how can I send an attachment. I dont care if I need to use a perl script just so long as I can pass it the from: email To: email and the body then the attachment and a subject line would be nice. Can anyone help. If testpage is plain text and you don't need to interface with sendmail as a requirement you could just: "cat /tmp/testpage.txt | mail -s -c -b ". ====================== if you really want an attachment you need to get a MUA (Mail User Agent) or a small program (perl with MIME::Lite, etc) to do the job. sendmail is a MTA (Mail Transfer Agent) and doesn't care for mail content (MIME attachments, etc), but only for delivery. Code: ## from: http://www.experts-exchange.com/Prog..._20208667.html use MIME::Lite; # The rest of script here ... my $msg = MIME::Lite->new ( From => $your_email, To => $fields{'membersemailaddress'}, Subject => 'Test Subject', Type => 'multipart/mixed' ); $msg->attach( Type =>'TEXT', Data =>"Dear $fields{'membersname'},\n\nTEST MESSAGE\n" ); foreach my $file ( qw(1.gif 2.gif 3.gif) ) { $msg->attach( Type => 'image/gif', Path => "../public/images/$file", Filename => $file, Disposition => 'attachment' ); } $msg->send; ================== you can use metasend and metamail to do what you are looking to do. I havnt tried either yet, but I know they support scripted mail with attachments. ================== Originally Posted by vivanguarda View Post Sorry, but sometimes I'm also scared about these years and in fact I don't understand anything about MTA! I don't have sendmail, postfix nor mutt... Anything running in this server. Well, if you want to send mail, you need a mail server. If it's not running, you shouldn't be surprised that you cant'. Quote: # /etc/rc.d/rc.sendmail start bash: /etc/rc.d/rc.sendmail: Permission denied Right...because that's a config file. Have you tried "/etc/init.d/sendmail start"? Quote: And this is my /var/log/maillog Mar 15 01:06:22 maq1 sendmail[2446]: gethostbyaddr(192.168.0.2) failed: 1 Mar 15 01:08:45 maq1 sendmail[2455]: r2F48j0t002455: from=root, size=219, class=0, nrcpts=1, msgid=<201303150408.r2F48j0t002455@maq1>, relay=root@localhost Mar 15 01:08:45 maq1 sendmail[2455]: r2F48j0t002455: to=vivanguarda2@ig.com.br, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30219, relay=[127.0.0.1] [127.0.0.1 ], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1[/I] I am reading a lot of LQ material but it's a difficult compreension. ======================== Home News Download Documentation Contact About msmtp msmtp is an SMTP client. In the default mode, it transmits a mail to an SMTP server which takes care of further delivery. To use this program with your mail user agent (MUA), create a configuration file with your mail account(s) and tell your MUA to call msmtp instead of /usr/sbin/sendmail. Features include: Sendmail compatible interface (command line options and exit codes) Support for multiple accounts TLS/SSL support including client certificates Support for Internationalized Domain Names (IDN) Many authentication methods Fast SMTP implementation using command pipelining DSN (Delivery Status Notification) support SOCKS proxy support msmtp runs on a wide variety of platforms. It needs little more than an ANSI C compiler and Berkeley-style sockets. It does not require any additional libraries, but it can use the following to enhance its feature set: GnuTLS The GnuTLS library provides TLS support. It is highly recommended. OpenSSL can be used as an alternative to GnuTLS, but this is discouraged. GNU SASL Using the GNU SASL library adds support for some exotic authentication methods. You really only need it if you want to use GSSAPI. GNU libidn2 On modern Linux systems with recent glibc and GnuTLS libraries, msmtp has automatic support for Internationalized Domain Names (IDN). On other systems, IDN support is available via libidn2. msmtp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ======================== COMPLETE SENDMAIL INSTRUCTIONS https://sendmail.org/~ca/email/doc8.12/op.html ======================== MORE MAIL INSTRUCTIONS https://tecadmin.net/ways-to-send-email-from-linux-command-line/ ======================== 1. Using ‘sendmail’ Command Sendmail is a most popular SMTP server used in most of Linux/Unix distribution. Sendmail allows sending email from command line. Use below instructions to send email using ‘sendmail‘ command. Created a file with email content: cat /tmp/email.txt Subject: Terminal Email Send Email Content line 1 Email Content line 2 Subject: line will be used as subject for email. Now send email using the following command. sendmail user@example.com < /tmp/email.txt Read more: Install and Configure Sendmail on CentOS/RHEL 2. Using ‘mail’ Command mail command is most popular command to send emails from Linux terminal. Use few of below examples to send an email. mail -s "Test Subject" user@example.com < /dev/null -s is used for defining subject for email. Also, you can send an attachment with this command. Use -a for mailx and -A for mailutils. mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null ======================== Blocklist Removal Center About Spamhaus | FAQs | News Blog The Spamhaus PBL Help I don't understand what to do about this? Ref: PBL183355 74.4.32.0/19 is listed on the Policy Block List (PBL) Outbound Email Policy of CenturyLink for this IP range: It is the policy of Embarq HSD that unauthenticated email sent from this IP address should be sent out only via the designated outbound mail server allocated to Embarq HSD customers. To find the hostname of the correct mail server to use, customers should consult the original signup documentation or contact Embarq HSD Technical Support. Removal Procedure If you are not using normal email software but instead are running a mail server and you are the owner of a Static IP address in the range 74.4.32.0/19 and you have a legitimate reason for operating a mail server on this IP, you can automatically remove (suppress) your static IP address from the PBL database. About The PBL The Spamhaus Policy Block List ("PBL") is an international anti-spam system maintained by The Spamhaus Project in conjunction with Internet Service Providers and is used by Internet networks to enforce inbound email policies. The PBL database lists end-user IP address ranges which should not be delivering unauthenticated email to any mail server except those provided for specifically for that customer's use. The PBL lists only IP addresses (not domains or email addresses). For full information on how the PBL operates please see the PBL Home page and the PBL Frequently Asked Questions. Associated Documents PBL Home PBL FAQs How Blocklists Work © 1998-2019 The Spamhaus Project Ltd. All rights reserved. Legal | Privacy Here -a is used for attachments. Use -A for debian based systems, which uses mailutils package. You may face issue: Bash: mail: command not found Also, we can add comma separated emails to send the email to multiple recipients together. mail -s "Test Email" user@example.com,user2@example.com < /dev/null ===================== How to Send Email from mailx Command in Linux Using Gmail’s SMTP By Eric Ma | In Linux | Updated on Feb 18, 2018 The heirloom mailx command in Linux is still providing service for guys like me, especially when we need to send email automatically by script. gmail is great. Now, how to use gmail’s smtp in mailx/mail? gmail is a little special since gmail’s smtp server requires tls authorization. The good news is that mailx supports it. Let’s look at how to use it. Sets the internal option variable and, in case of a string option, assigns value to it. Note, that when setting from variable, domain name of host is automatically added if value does not contain any. If you want to enter from address with owner’s name, you can use, for example, following format: -S "from=System User " This is an all-in-one command that sends email to $TO_EMAIL_ADDRESS $ mailx -v -s "$EMAIL_SUBJECT" \ -S smtp-use-starttls \ -S ssl-verify=ignore \ -S smtp-auth=login \ -S smtp=smtp://smtp.gmail.com:587 \ -S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \ -S smtp-auth-user=$FROM_EMAIL_ADDRESS \ -S smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD \ -S ssl-verify=ignore \ $TO_EMAIL_ADDRESS Replace the $... above with the value that is actually used. This command will ask for the email content. Type in the mail content and after finishing the email, use “Ctrl+d” to tell mailx you have finished. Then this mail will be sent out through gmail’s smtp server. You can also use pipe like this: echo "The mail content" | mail -v -s ... ============= Security notes on passwords you may consider not setting -S smtp-auth-password and input it each time you use this command. Passwords in the command line can be seen by other users on the system. Gmail now supports "App Password" if you are using Google’s 2-Step verification and you will need to use it instead of your Gmail’s password. You can generate an "App Password" for mailx so it can be easily revoked in case it leaked out. Go to this URL: https://myaccount.google.com/apppasswords . Click on “Select App” → “Other”, type “mailx”, and hit “Generate”. You will get a password used by mailx. (thanks to Ben for the notes). About nssdb used by mailx Most Linux system’s default nssdb should be already updated so that gmail is good with it. But if your system does not have an updated nssdb, you may consider using Firefox’s instead by adding such option -S nss-config-dir=~/.mozilla/firefox/yyyyyyyy.default/ Find out Firefox’s profile directory in the home directory which commonly has a format like this: ~/.mozilla/firefox/yyyyyyyy.default yyyyyyyy is a random string that’s different for different users. You can easily find it out by looking into the directory ~/.mozilla/firefox. Use mailx configuration file There are too many options in the above command? Yes… I must confess so. We can write most of them into mailx/mail’s configuration file ~/.mailrc set smtp-use-starttls set ssl-verify=ignore set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set smtp-auth-user=$FROM_EMAIL_ADDRESS set smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD set from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" For better security, you may set the mode of ~/.mailrc to 600 by chmod 600 ~/.mailrc. The variables set are the same as those used in the "all in one command". When sending mails, use this command: $ mailx -v -s "$EMAIL_SUBJECT" $TO_EMAIL_ADDRESS Or $ echo "The mail content" | mail -v -s "$EMAIL_SUBJECT" $TO_EMAIL_ADDRESS Then, time to enjoy it!