Ways to add recipients in mailx












1














What options do I have for adding recipients to email when using mailx (or variations thereof)? The ones I know about are:




  • Manually type email address character by character from memory

  • Enter an alias that I have stored in .mailrc earlier


Are there other options like an address book created from email addresses I have sent email to earlier, that can be navigated with the cursor keys or narrowed down by auto-complete?










share|improve this question



























    1














    What options do I have for adding recipients to email when using mailx (or variations thereof)? The ones I know about are:




    • Manually type email address character by character from memory

    • Enter an alias that I have stored in .mailrc earlier


    Are there other options like an address book created from email addresses I have sent email to earlier, that can be navigated with the cursor keys or narrowed down by auto-complete?










    share|improve this question

























      1












      1








      1







      What options do I have for adding recipients to email when using mailx (or variations thereof)? The ones I know about are:




      • Manually type email address character by character from memory

      • Enter an alias that I have stored in .mailrc earlier


      Are there other options like an address book created from email addresses I have sent email to earlier, that can be navigated with the cursor keys or narrowed down by auto-complete?










      share|improve this question













      What options do I have for adding recipients to email when using mailx (or variations thereof)? The ones I know about are:




      • Manually type email address character by character from memory

      • Enter an alias that I have stored in .mailrc earlier


      Are there other options like an address book created from email addresses I have sent email to earlier, that can be navigated with the cursor keys or narrowed down by auto-complete?







      mailx mail-command






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 18 '18 at 14:12









      forthrinforthrin

      8721121




      8721121






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Forthrin, I could not find an elegant solution to this problem. But I did a little thinking, and a possible workaround would be outlined like this:



          Make a directory called 'recipients', create dummy files named after the email addresses you desire to send to, use auto-complete inside this directory.



          mkdir recipients
          cd recipients
          touch me@example.com
          mail -s "stuff" 'me@example.com' < logfile.txt


          Single quotes here to help avoid escaping the '' that would appear.



          I know it's not pretty, but you could doll this up by pulling from a text file of email addresses and cobbling an auto-complete together that way. I'm unsure how to go about that, though. Someone smarter than me could chime in.



          Further, you can scour your previous history and maillog to look at the mails you've already sent and grab those addresses, then toss them into the recipients folder. Now you have a folder of recipients with which tab completion will work (satisfying your auto-complete request).



          Not the best solution, but I don't see any feature in mailx for address books.






          share|improve this answer





















          • Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
            – forthrin
            May 18 '18 at 16:29



















          0














          A solution would be to use a wrapper to save addresses and bash completion to retrieve them:



          address_book=${HOME}/.address
          mailx() {
          #loop through all args
          for i; do
          # does this look like an email address
          if grep -xqE '[[:alnum:]_.+-]+@[[:alnum:]-]+.[[:alnum:].-]+' <<< "${i}" && ! grep -xqF "${i}" "${address_book}"; then
          echo "${i}" >> "${address_book}"
          fi
          done
          /usr/bin/mailx "${@}"
          }
          _mailx_completion() {
          if [[ ! -f ${address_book} ]] ; then
          return
          fi
          # Only add each email once
          emails=($(grep -xvf<(echo "${COMP_WORDS[*]}"|tr ' ' 'n'))"${address_book}")
          if [[ ${#emails} -eq 0 ]] ; then
          return
          fi
          # list emails
          COMPREPLY=( $(compgen -W "${emails[@]}" "${COMP_WORDS[${COMP_CWORD}]}") )
          }
          complete -F _mailx_completion mailx


          Add to your ‘.bashrc’



          Explanation:



          After running mailx, go through each argument passed to mailx and see if it looks like an email address and if it doesn't already exist then our "address book".



          When on the command line the bash autocomplete will add the email addresses for you at the end after you press tab. This function ensures we are not adding the same email address multiple times.






          share|improve this answer























          • Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
            – forthrin
            2 days ago










          • @forthrin - added comments and explanation
            – LukeM
            yesterday











          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%2f444619%2fways-to-add-recipients-in-mailx%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Forthrin, I could not find an elegant solution to this problem. But I did a little thinking, and a possible workaround would be outlined like this:



          Make a directory called 'recipients', create dummy files named after the email addresses you desire to send to, use auto-complete inside this directory.



          mkdir recipients
          cd recipients
          touch me@example.com
          mail -s "stuff" 'me@example.com' < logfile.txt


          Single quotes here to help avoid escaping the '' that would appear.



          I know it's not pretty, but you could doll this up by pulling from a text file of email addresses and cobbling an auto-complete together that way. I'm unsure how to go about that, though. Someone smarter than me could chime in.



          Further, you can scour your previous history and maillog to look at the mails you've already sent and grab those addresses, then toss them into the recipients folder. Now you have a folder of recipients with which tab completion will work (satisfying your auto-complete request).



          Not the best solution, but I don't see any feature in mailx for address books.






          share|improve this answer





















          • Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
            – forthrin
            May 18 '18 at 16:29
















          1














          Forthrin, I could not find an elegant solution to this problem. But I did a little thinking, and a possible workaround would be outlined like this:



          Make a directory called 'recipients', create dummy files named after the email addresses you desire to send to, use auto-complete inside this directory.



          mkdir recipients
          cd recipients
          touch me@example.com
          mail -s "stuff" 'me@example.com' < logfile.txt


          Single quotes here to help avoid escaping the '' that would appear.



          I know it's not pretty, but you could doll this up by pulling from a text file of email addresses and cobbling an auto-complete together that way. I'm unsure how to go about that, though. Someone smarter than me could chime in.



          Further, you can scour your previous history and maillog to look at the mails you've already sent and grab those addresses, then toss them into the recipients folder. Now you have a folder of recipients with which tab completion will work (satisfying your auto-complete request).



          Not the best solution, but I don't see any feature in mailx for address books.






          share|improve this answer





















          • Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
            – forthrin
            May 18 '18 at 16:29














          1












          1








          1






          Forthrin, I could not find an elegant solution to this problem. But I did a little thinking, and a possible workaround would be outlined like this:



          Make a directory called 'recipients', create dummy files named after the email addresses you desire to send to, use auto-complete inside this directory.



          mkdir recipients
          cd recipients
          touch me@example.com
          mail -s "stuff" 'me@example.com' < logfile.txt


          Single quotes here to help avoid escaping the '' that would appear.



          I know it's not pretty, but you could doll this up by pulling from a text file of email addresses and cobbling an auto-complete together that way. I'm unsure how to go about that, though. Someone smarter than me could chime in.



          Further, you can scour your previous history and maillog to look at the mails you've already sent and grab those addresses, then toss them into the recipients folder. Now you have a folder of recipients with which tab completion will work (satisfying your auto-complete request).



          Not the best solution, but I don't see any feature in mailx for address books.






          share|improve this answer












          Forthrin, I could not find an elegant solution to this problem. But I did a little thinking, and a possible workaround would be outlined like this:



          Make a directory called 'recipients', create dummy files named after the email addresses you desire to send to, use auto-complete inside this directory.



          mkdir recipients
          cd recipients
          touch me@example.com
          mail -s "stuff" 'me@example.com' < logfile.txt


          Single quotes here to help avoid escaping the '' that would appear.



          I know it's not pretty, but you could doll this up by pulling from a text file of email addresses and cobbling an auto-complete together that way. I'm unsure how to go about that, though. Someone smarter than me could chime in.



          Further, you can scour your previous history and maillog to look at the mails you've already sent and grab those addresses, then toss them into the recipients folder. Now you have a folder of recipients with which tab completion will work (satisfying your auto-complete request).



          Not the best solution, but I don't see any feature in mailx for address books.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 18 '18 at 15:57









          Kristopher KahnKristopher Kahn

          364




          364












          • Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
            – forthrin
            May 18 '18 at 16:29


















          • Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
            – forthrin
            May 18 '18 at 16:29
















          Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
          – forthrin
          May 18 '18 at 16:29




          Thanks for sharing an amusing solution! I'll keep the question open for further (creative) suggestions.
          – forthrin
          May 18 '18 at 16:29













          0














          A solution would be to use a wrapper to save addresses and bash completion to retrieve them:



          address_book=${HOME}/.address
          mailx() {
          #loop through all args
          for i; do
          # does this look like an email address
          if grep -xqE '[[:alnum:]_.+-]+@[[:alnum:]-]+.[[:alnum:].-]+' <<< "${i}" && ! grep -xqF "${i}" "${address_book}"; then
          echo "${i}" >> "${address_book}"
          fi
          done
          /usr/bin/mailx "${@}"
          }
          _mailx_completion() {
          if [[ ! -f ${address_book} ]] ; then
          return
          fi
          # Only add each email once
          emails=($(grep -xvf<(echo "${COMP_WORDS[*]}"|tr ' ' 'n'))"${address_book}")
          if [[ ${#emails} -eq 0 ]] ; then
          return
          fi
          # list emails
          COMPREPLY=( $(compgen -W "${emails[@]}" "${COMP_WORDS[${COMP_CWORD}]}") )
          }
          complete -F _mailx_completion mailx


          Add to your ‘.bashrc’



          Explanation:



          After running mailx, go through each argument passed to mailx and see if it looks like an email address and if it doesn't already exist then our "address book".



          When on the command line the bash autocomplete will add the email addresses for you at the end after you press tab. This function ensures we are not adding the same email address multiple times.






          share|improve this answer























          • Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
            – forthrin
            2 days ago










          • @forthrin - added comments and explanation
            – LukeM
            yesterday
















          0














          A solution would be to use a wrapper to save addresses and bash completion to retrieve them:



          address_book=${HOME}/.address
          mailx() {
          #loop through all args
          for i; do
          # does this look like an email address
          if grep -xqE '[[:alnum:]_.+-]+@[[:alnum:]-]+.[[:alnum:].-]+' <<< "${i}" && ! grep -xqF "${i}" "${address_book}"; then
          echo "${i}" >> "${address_book}"
          fi
          done
          /usr/bin/mailx "${@}"
          }
          _mailx_completion() {
          if [[ ! -f ${address_book} ]] ; then
          return
          fi
          # Only add each email once
          emails=($(grep -xvf<(echo "${COMP_WORDS[*]}"|tr ' ' 'n'))"${address_book}")
          if [[ ${#emails} -eq 0 ]] ; then
          return
          fi
          # list emails
          COMPREPLY=( $(compgen -W "${emails[@]}" "${COMP_WORDS[${COMP_CWORD}]}") )
          }
          complete -F _mailx_completion mailx


          Add to your ‘.bashrc’



          Explanation:



          After running mailx, go through each argument passed to mailx and see if it looks like an email address and if it doesn't already exist then our "address book".



          When on the command line the bash autocomplete will add the email addresses for you at the end after you press tab. This function ensures we are not adding the same email address multiple times.






          share|improve this answer























          • Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
            – forthrin
            2 days ago










          • @forthrin - added comments and explanation
            – LukeM
            yesterday














          0












          0








          0






          A solution would be to use a wrapper to save addresses and bash completion to retrieve them:



          address_book=${HOME}/.address
          mailx() {
          #loop through all args
          for i; do
          # does this look like an email address
          if grep -xqE '[[:alnum:]_.+-]+@[[:alnum:]-]+.[[:alnum:].-]+' <<< "${i}" && ! grep -xqF "${i}" "${address_book}"; then
          echo "${i}" >> "${address_book}"
          fi
          done
          /usr/bin/mailx "${@}"
          }
          _mailx_completion() {
          if [[ ! -f ${address_book} ]] ; then
          return
          fi
          # Only add each email once
          emails=($(grep -xvf<(echo "${COMP_WORDS[*]}"|tr ' ' 'n'))"${address_book}")
          if [[ ${#emails} -eq 0 ]] ; then
          return
          fi
          # list emails
          COMPREPLY=( $(compgen -W "${emails[@]}" "${COMP_WORDS[${COMP_CWORD}]}") )
          }
          complete -F _mailx_completion mailx


          Add to your ‘.bashrc’



          Explanation:



          After running mailx, go through each argument passed to mailx and see if it looks like an email address and if it doesn't already exist then our "address book".



          When on the command line the bash autocomplete will add the email addresses for you at the end after you press tab. This function ensures we are not adding the same email address multiple times.






          share|improve this answer














          A solution would be to use a wrapper to save addresses and bash completion to retrieve them:



          address_book=${HOME}/.address
          mailx() {
          #loop through all args
          for i; do
          # does this look like an email address
          if grep -xqE '[[:alnum:]_.+-]+@[[:alnum:]-]+.[[:alnum:].-]+' <<< "${i}" && ! grep -xqF "${i}" "${address_book}"; then
          echo "${i}" >> "${address_book}"
          fi
          done
          /usr/bin/mailx "${@}"
          }
          _mailx_completion() {
          if [[ ! -f ${address_book} ]] ; then
          return
          fi
          # Only add each email once
          emails=($(grep -xvf<(echo "${COMP_WORDS[*]}"|tr ' ' 'n'))"${address_book}")
          if [[ ${#emails} -eq 0 ]] ; then
          return
          fi
          # list emails
          COMPREPLY=( $(compgen -W "${emails[@]}" "${COMP_WORDS[${COMP_CWORD}]}") )
          }
          complete -F _mailx_completion mailx


          Add to your ‘.bashrc’



          Explanation:



          After running mailx, go through each argument passed to mailx and see if it looks like an email address and if it doesn't already exist then our "address book".



          When on the command line the bash autocomplete will add the email addresses for you at the end after you press tab. This function ensures we are not adding the same email address multiple times.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered Jan 4 at 4:46









          LukeMLukeM

          3,43932140




          3,43932140












          • Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
            – forthrin
            2 days ago










          • @forthrin - added comments and explanation
            – LukeM
            yesterday


















          • Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
            – forthrin
            2 days ago










          • @forthrin - added comments and explanation
            – LukeM
            yesterday
















          Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
          – forthrin
          2 days ago




          Very interesting! Could you explain step-by-step how this works? What can I expect to happen if I run this?
          – forthrin
          2 days ago












          @forthrin - added comments and explanation
          – LukeM
          yesterday




          @forthrin - added comments and explanation
          – LukeM
          yesterday


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f444619%2fways-to-add-recipients-in-mailx%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

          How to make a Squid Proxy server?

          Is this a new Fibonacci Identity?

          19世紀