Sunday, May 5, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 4914  / 1 Year ago, fri, december 23, 2022, 1:32:39

I'm trying to send an email using bash script.



I tried using the following in the bash script with no success as I execute the script it asks for CC:



#!/bin/bash
recipient="[email protected]"
mail -s "This is a test mail" "$recipient"


but nothing seems to work as I want it to be automated.



Also I want to send a message with the mail I went through different tutorials but in every tutorial a message is written in a text file then the file is sent but can't I write a message with the mail command itself and not save it to any file and send it. Please Help.



P.S.



I just want the script to do the following



If a particular operation is complete then it sends an email to the recipient with a subject and a message saying operation is completed successfully.


More From » command-line

 Answers
0

Sending a body with GNU mailutils in a script should work like this:



echo -e "body of message 
And use newlines for new lines." | mail -s "the subject" [email protected]


It should not ask for a CC address interactively in this mode (reading from stdin using the pipe |).


[#30655] Saturday, December 24, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eryeath

Total Points: 122
Total Questions: 121
Total Answers: 112

Location: Saint Helena
Member since Fri, Aug 26, 2022
2 Years ago
;