0

I have a script to send out email from a particular email address. Still mails are going as username@hostname of the server.

#!/bin/bash
# script to send simple email
# Email To ?
EMAIL="sending_to_address"
# Email text/message
EMAILMESSAGE="/mailmessage.txt"
/bin/mail -s "SUBJECT" "$EMAIL" < $EMAILMESSAGE -- -f from_email_address

Please correct it so that I can send mails as from_email_address rather than the hostname.

user3349526
  • 1
  • 1
  • 1

2 Answers2

0
#!/bin/bash
# script to send simple email
# Email To ?
EMAIL="sending_to_address"
# Email text/message
EMAILMESSAGE="/mailmessage.txt"
/bin/mail -s "SUBJECT" "$EMAIL" < $EMAILMESSAGE -- -f from_email_address

Are you sending the email for your lan? Are you port forwarded if outside? Unless this is for a school project I'd go with using PHP.

Blake Nic
  • 13
  • 1
  • 7
  • I am running a backuppc for backing up my servers and this script is used to send out the status after completing the backup. mails will be going out to the public email addresses outside (gmail,exchange etc). – user3349526 Feb 25 '14 at 04:53
  • In that case you will want to port forward your modem. Also check out the response this guy made: http://stackoverflow.com/questions/9038926/how-to-send-a-simple-email-from-a-windows-batch-file – Blake Nic Feb 25 '14 at 05:14
  • I am able to do the same using sendmail. But the issue is I am not able to put the content of a text file as a body of the email. If I can figure out that, would be enough. Following is my sendmail command : `/usr/sbin/sendmail destination_email_address < – user3349526 Feb 25 '14 at 05:18
  • Set a variable with the contents of /tmp/message.txt and then call that varible in EMAILMESSAGE. – Blake Nic Feb 25 '14 at 05:22
  • Also try something like this: mail -s "mail subject" youremail@email.com -a "Reply-To: " <<< "/mailmessage.txt" – Blake Nic Feb 25 '14 at 05:32
  • I have saved the contents of the text file to a variable and called inside sendmail. That works great. normal mail function is not working though.... Thanks Blake – user3349526 Feb 25 '14 at 05:45
0

There is a similar post on superuser which will solve your problem. Check here.

I hope it helps.

Community
  • 1
  • 1
Gaurav
  • 1,005
  • 3
  • 14
  • 33