How to set mail subject using variable and ensure attachment is not included in email bodyLinux mail,...

Did Alan Turing's student Robin Gandy assert that Charles Babbage had no notion of a universal computing machine?

Has Rey's new lightsaber been seen before in canon or legends?

Is there a name for this metric: TN / (TN + FN)?

'Hard work never hurt anyone' Why not 'hurts'?

How has NASA's mission operations software architecture evolved?

How to anonymously report the Establishment Clause being broken?

When making yogurt, why doesn't bad bacteria grow as well?

How do I make my fill-in-the-blank exercise more obvious?

What are the main differences in the druid class between 5th edition and 3.5 edition?

Does this bike use hydraulic brakes?

What is the difference between "wie" and "nach" in "Klingt wie/nach..."

How many days for hunting?

What is hot spotting in the context of adding files to tempdb?

'This one' as a pronoun

Question about derivation of kinematics equations

What is the significance of 104% for throttle power and rotor speed?

Punishment in pacifist society

Are there photos of the Apollo LM showing disturbed lunar soil resulting from descent engine exhaust?

Splitting polygons at narrowest part using R?

What is the most likely cause of short, quick, and useless reviews?

Do index funds really have double-digit percents annual return rates?

Is it rude to ask my opponent to resign an online game when they have a lost endgame?

Travel to USA with a stuffed puppet

Can a country avoid prosecution for crimes against humanity by denying it happened?



How to set mail subject using variable and ensure attachment is not included in email body


Linux mail, attachement with uuencode works until I add headersModify date in email header using script with mailxBold and Underline using echo with emailSSMTP: How to send email with both a body and attachmenthow to send multiple attachment in 1 email using uuencodeForwarding an email as an attachment with a bash shell script, or applescriptmail/mailx: How to specify recipents with full names?Unix--Send attachment, subject and body of the mail using mailxMailx command to send the email to gmail account with content type as Content-Type: text/htmlhow to send a mail with attachment using sendmail command in unix






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have the following shell script fragment.



var_name='ZZPCI'
for emailadd in `cat /tmp/email_list.tmp`
do
subject_text="Subject with Var Name "$var_name
subj_text_novar="Subject without Var Name"
email_mssge="this is the message with variable name "$var_name
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subject_text" "$emailadd"
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subj_text_novar" "$emailadd"
done


What it does is
a. Sets the variable var_name
b. Reads through the list of email addresses stored in /tmp/email_list.tmp
c. Compiles and sends an email with /tmp/my_report.txt (plain text file) as an attachment



The script is intended to run on a number of different servers, so var_name will change with each server.
The mail command with $subj_text_novar, (does not include $var_name in the subject string), sends the email correctly .
However the mail command with $subject_text which does include $var_name places the contents of the attachment into the main body of the email.
As far as I can make out, it is the actual $-sign causing the problem because hardcoding the var_name value into the string is fine but I don't see why because surely var_name is just a concatenated string
So, how can I set the subject for mail so it includes $var_name and my text file is sent as an attachment?



I am running this on SuSE 11.3 but the solution ideally needs to work on AIX 6.1 and HP UX11.31 as well



Regards










share|improve this question

















bumped to the homepage by Community 45 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















  • Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

    – roaima
    Jul 21 '15 at 15:32













  • beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

    – Jeff Schaller
    Jul 21 '15 at 15:37











  • Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

    – Noj
    Jul 21 '15 at 16:02













  • And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

    – Noj
    Jul 21 '15 at 16:06


















0















I have the following shell script fragment.



var_name='ZZPCI'
for emailadd in `cat /tmp/email_list.tmp`
do
subject_text="Subject with Var Name "$var_name
subj_text_novar="Subject without Var Name"
email_mssge="this is the message with variable name "$var_name
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subject_text" "$emailadd"
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subj_text_novar" "$emailadd"
done


What it does is
a. Sets the variable var_name
b. Reads through the list of email addresses stored in /tmp/email_list.tmp
c. Compiles and sends an email with /tmp/my_report.txt (plain text file) as an attachment



The script is intended to run on a number of different servers, so var_name will change with each server.
The mail command with $subj_text_novar, (does not include $var_name in the subject string), sends the email correctly .
However the mail command with $subject_text which does include $var_name places the contents of the attachment into the main body of the email.
As far as I can make out, it is the actual $-sign causing the problem because hardcoding the var_name value into the string is fine but I don't see why because surely var_name is just a concatenated string
So, how can I set the subject for mail so it includes $var_name and my text file is sent as an attachment?



I am running this on SuSE 11.3 but the solution ideally needs to work on AIX 6.1 and HP UX11.31 as well



Regards










share|improve this question

















bumped to the homepage by Community 45 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















  • Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

    – roaima
    Jul 21 '15 at 15:32













  • beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

    – Jeff Schaller
    Jul 21 '15 at 15:37











  • Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

    – Noj
    Jul 21 '15 at 16:02













  • And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

    – Noj
    Jul 21 '15 at 16:06














0












0








0








I have the following shell script fragment.



var_name='ZZPCI'
for emailadd in `cat /tmp/email_list.tmp`
do
subject_text="Subject with Var Name "$var_name
subj_text_novar="Subject without Var Name"
email_mssge="this is the message with variable name "$var_name
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subject_text" "$emailadd"
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subj_text_novar" "$emailadd"
done


What it does is
a. Sets the variable var_name
b. Reads through the list of email addresses stored in /tmp/email_list.tmp
c. Compiles and sends an email with /tmp/my_report.txt (plain text file) as an attachment



The script is intended to run on a number of different servers, so var_name will change with each server.
The mail command with $subj_text_novar, (does not include $var_name in the subject string), sends the email correctly .
However the mail command with $subject_text which does include $var_name places the contents of the attachment into the main body of the email.
As far as I can make out, it is the actual $-sign causing the problem because hardcoding the var_name value into the string is fine but I don't see why because surely var_name is just a concatenated string
So, how can I set the subject for mail so it includes $var_name and my text file is sent as an attachment?



I am running this on SuSE 11.3 but the solution ideally needs to work on AIX 6.1 and HP UX11.31 as well



Regards










share|improve this question
















I have the following shell script fragment.



var_name='ZZPCI'
for emailadd in `cat /tmp/email_list.tmp`
do
subject_text="Subject with Var Name "$var_name
subj_text_novar="Subject without Var Name"
email_mssge="this is the message with variable name "$var_name
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subject_text" "$emailadd"
echo "$email_mssge"|mailx -a /tmp/my_report.txt -s "$subj_text_novar" "$emailadd"
done


What it does is
a. Sets the variable var_name
b. Reads through the list of email addresses stored in /tmp/email_list.tmp
c. Compiles and sends an email with /tmp/my_report.txt (plain text file) as an attachment



The script is intended to run on a number of different servers, so var_name will change with each server.
The mail command with $subj_text_novar, (does not include $var_name in the subject string), sends the email correctly .
However the mail command with $subject_text which does include $var_name places the contents of the attachment into the main body of the email.
As far as I can make out, it is the actual $-sign causing the problem because hardcoding the var_name value into the string is fine but I don't see why because surely var_name is just a concatenated string
So, how can I set the subject for mail so it includes $var_name and my text file is sent as an attachment?



I am running this on SuSE 11.3 but the solution ideally needs to work on AIX 6.1 and HP UX11.31 as well



Regards







linux email solaris aix mailx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 21 '15 at 15:43









roaima

49.4k7 gold badges66 silver badges133 bronze badges




49.4k7 gold badges66 silver badges133 bronze badges










asked Jul 21 '15 at 15:28









NojNoj

11 silver badge1 bronze badge




11 silver badge1 bronze badge






bumped to the homepage by Community 45 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









bumped to the homepage by Community 45 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 45 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

    – roaima
    Jul 21 '15 at 15:32













  • beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

    – Jeff Schaller
    Jul 21 '15 at 15:37











  • Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

    – Noj
    Jul 21 '15 at 16:02













  • And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

    – Noj
    Jul 21 '15 at 16:06



















  • Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

    – roaima
    Jul 21 '15 at 15:32













  • beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

    – Jeff Schaller
    Jul 21 '15 at 15:37











  • Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

    – Noj
    Jul 21 '15 at 16:02













  • And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

    – Noj
    Jul 21 '15 at 16:06

















Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

– roaima
Jul 21 '15 at 15:32







Quote the variables. For example, subject_text="Subject with Var Name $var_name". Do you need to send a separate message to each recipient in /tmp/email_list.tmp? If not, you can discard the loop and put $(cat /tmp/email_list.tmp) in place of "$emailadd" on the two mailx command lines

– roaima
Jul 21 '15 at 15:32















beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

– Jeff Schaller
Jul 21 '15 at 15:37





beware: the -a flag to mailx may not exist on your AIX and/or HPUX machines.

– Jeff Schaller
Jul 21 '15 at 15:37













Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

– Noj
Jul 21 '15 at 16:02







Thanks to roaima for the answer. In fact I had tried this before without joy. But roaima's comment made me re-evaluate and in the context of the shell fragment yes it worked. However I was actually deriving var_name from an Oracle database, (probably I should've mentioned it but to be honest I didn't think that was the issue). Anyway by doing var_name=echo $dbs_value I was able to employ roaima's solution.

– Noj
Jul 21 '15 at 16:02















And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

– Noj
Jul 21 '15 at 16:06





And thanks Jeff Schaller about AIX & HP. I'll investigate both OS's to see if there are alternatives

– Noj
Jul 21 '15 at 16:06










1 Answer
1






active

oldest

votes


















0
















I have something for you using heirloom-mailx:



enviaremail() {
values=$(echo "$@" | tr -d 'n')
listargs=()
listargs+=($values)
heirloom-mailx $( attachment=""
for (( a = 5; a < ${#listargs[@]}; a++ )); do
attachment=$(echo "-a ${listargs[a]} ")
echo "${attachment}"
done) -v -s "${titulo}"
-S smtp-use-starttls
-S ssl-verify=ignore
-S smtp-auth=login
-S smtp=smtp://$1
-S from="${2}"
-S smtp-auth-user=$3
-S smtp-auth-password=$4
-S ssl-verify=ignore
$5 < ${cuerpo}
}


function call:
enviaremail smtp.mailserver:port from_address authuser 'pass' destination list of attachments separated by space



In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function.
You can put the function as a script (mailsend.sh) in the path and then just use it in your scripts with source or place it in your .bashrc file.



Best Regards






share|improve this answer




























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f217402%2fhow-to-set-mail-subject-using-variable-and-ensure-attachment-is-not-included-in%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    I have something for you using heirloom-mailx:



    enviaremail() {
    values=$(echo "$@" | tr -d 'n')
    listargs=()
    listargs+=($values)
    heirloom-mailx $( attachment=""
    for (( a = 5; a < ${#listargs[@]}; a++ )); do
    attachment=$(echo "-a ${listargs[a]} ")
    echo "${attachment}"
    done) -v -s "${titulo}"
    -S smtp-use-starttls
    -S ssl-verify=ignore
    -S smtp-auth=login
    -S smtp=smtp://$1
    -S from="${2}"
    -S smtp-auth-user=$3
    -S smtp-auth-password=$4
    -S ssl-verify=ignore
    $5 < ${cuerpo}
    }


    function call:
    enviaremail smtp.mailserver:port from_address authuser 'pass' destination list of attachments separated by space



    In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function.
    You can put the function as a script (mailsend.sh) in the path and then just use it in your scripts with source or place it in your .bashrc file.



    Best Regards






    share|improve this answer






























      0
















      I have something for you using heirloom-mailx:



      enviaremail() {
      values=$(echo "$@" | tr -d 'n')
      listargs=()
      listargs+=($values)
      heirloom-mailx $( attachment=""
      for (( a = 5; a < ${#listargs[@]}; a++ )); do
      attachment=$(echo "-a ${listargs[a]} ")
      echo "${attachment}"
      done) -v -s "${titulo}"
      -S smtp-use-starttls
      -S ssl-verify=ignore
      -S smtp-auth=login
      -S smtp=smtp://$1
      -S from="${2}"
      -S smtp-auth-user=$3
      -S smtp-auth-password=$4
      -S ssl-verify=ignore
      $5 < ${cuerpo}
      }


      function call:
      enviaremail smtp.mailserver:port from_address authuser 'pass' destination list of attachments separated by space



      In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function.
      You can put the function as a script (mailsend.sh) in the path and then just use it in your scripts with source or place it in your .bashrc file.



      Best Regards






      share|improve this answer




























        0














        0










        0









        I have something for you using heirloom-mailx:



        enviaremail() {
        values=$(echo "$@" | tr -d 'n')
        listargs=()
        listargs+=($values)
        heirloom-mailx $( attachment=""
        for (( a = 5; a < ${#listargs[@]}; a++ )); do
        attachment=$(echo "-a ${listargs[a]} ")
        echo "${attachment}"
        done) -v -s "${titulo}"
        -S smtp-use-starttls
        -S ssl-verify=ignore
        -S smtp-auth=login
        -S smtp=smtp://$1
        -S from="${2}"
        -S smtp-auth-user=$3
        -S smtp-auth-password=$4
        -S ssl-verify=ignore
        $5 < ${cuerpo}
        }


        function call:
        enviaremail smtp.mailserver:port from_address authuser 'pass' destination list of attachments separated by space



        In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function.
        You can put the function as a script (mailsend.sh) in the path and then just use it in your scripts with source or place it in your .bashrc file.



        Best Regards






        share|improve this answer













        I have something for you using heirloom-mailx:



        enviaremail() {
        values=$(echo "$@" | tr -d 'n')
        listargs=()
        listargs+=($values)
        heirloom-mailx $( attachment=""
        for (( a = 5; a < ${#listargs[@]}; a++ )); do
        attachment=$(echo "-a ${listargs[a]} ")
        echo "${attachment}"
        done) -v -s "${titulo}"
        -S smtp-use-starttls
        -S ssl-verify=ignore
        -S smtp-auth=login
        -S smtp=smtp://$1
        -S from="${2}"
        -S smtp-auth-user=$3
        -S smtp-auth-password=$4
        -S ssl-verify=ignore
        $5 < ${cuerpo}
        }


        function call:
        enviaremail smtp.mailserver:port from_address authuser 'pass' destination list of attachments separated by space



        In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function.
        You can put the function as a script (mailsend.sh) in the path and then just use it in your scripts with source or place it in your .bashrc file.



        Best Regards







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 10 '18 at 11:21









        Ivo YordanovIvo Yordanov

        215 bronze badges




        215 bronze badges

































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f217402%2fhow-to-set-mail-subject-using-variable-and-ensure-attachment-is-not-included-in%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...