Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2013
    Location
    LA
    Posts
    18

    send email with shell script

    this is shell script for send mail

    it works well

    but it gose to spem

    i think becouse sender is "root@localhost.localhost"

    how do i change sender ?

    OS : centos 4.7 32bit

    thank you.

    function send_notification
    {
    if [ -s $PING_OUTFILE -a "$MAILOUT" = "TRUE" ];
    then
    case $UNAME in
    AIX|HP-UX|Linux) SENDMAIL="/usr/sbin/sendmail"
    ;;
    SunOS) SENDMAIL="/usr/lib/sendmail"
    ;;
    esac

    echo "\nSending e-mail notification"
    $SENDMAIL -f root@$THISHOST $MAILLIST < $PING_OUTFILE
    fi
    }

  2. #2
    Join Date
    Aug 2013
    Posts
    224
    Are you running the server on localhost, or are you running it on a public domain/IP?

  3. #3
    Join Date
    Feb 2012
    Posts
    231
    Login as a user and execute the script. It will send it as "user@....."

    What is the MTA on your server ? Sendmail itself or EXIM/Postfix ?
    WEBUZO - Single User Control Panel for your VPS/Cloud/Server (CentOS/Ubuntu)
    Install NGINX, Apache, MySQL, LAMP, LEMP, PHP, Java and 310+ popular scripts by a CLICK
    Email Server, Database Management, Domain Management, FTP Management, CSF, CRON

  4. #4
    Join Date
    Jun 2010
    Location
    Manchester, UK
    Posts
    179
    Agree with Valley.
    As far as I know, you would need to login using the user account you wish to send the mail from.

    I use Python for this type of thing nowadays, as it offers a wealth of options for just about whatever you want to code (i.e. SMTP authentication).
    Farbyte Ltd [UK] ♦ Professional UK Cloud Hosting ♦ Tel: +44 (0)843 532 0744
    cPanel® web hosting since 2006.
    Distributed Optane SSD caching cloud VPS
    ♦ Hosting ♦ Domains ♦ SSL Certificates ♦ VPS

  5. #5
    Join Date
    Apr 2011
    Location
    Charlotte, NC
    Posts
    104
    Why not just use the the 'mail' command?

    http://linux.die.net/man/1/mail
    Adam Hahn
    Software Engineer / System Administrator / Database Engineer

  6. #6
    Join Date
    Mar 2005
    Location
    Ten1/0/2
    Posts
    2,529
    use mailx for sending email from a script - much easier and gives full access to set any/all headers as required including from address.
    CPanel Shared and Reseller Hosting, OpenVZ VPS Hosting. West Coast (LA) Servers and Nodes
    Running Linux since 1.0.8 Kernel!
    Providing Internet Services since 1995 and Hosting Since 2004

  7. #7
    Join Date
    Oct 2013
    Location
    LA
    Posts
    18

    Thank you

    i will check it mailx function

    thank you for helping me

  8. #8
    You could also connect directly yo your relay server using telnet or nc, like

    printf "helo aef\r\nmail from: <blah@blah.com>\r\nrcpt to: <foo@bar.com>\r\ndata\r\nsubject: test\r\n\r\ntest\r\n.\r\n" | nc mail.relay.foo.bar.com 25

  9. #9
    This script you can use to send mails from shell working on Linux and FreeBSD

    PHP Code:
    #! /bin/bash

     
    TO_ADDRESS=”somebody@webhostingtalk.com”
     FROM_ADDRESS
    =”me@webhostingtalk.com”
     SUBJECT
    =”where i can find blueberries :)
     BODY
    =”I love coding”
     
    echo ${BODY MESSAGE}| mail -${SUBJECT } ${TO_ADDRESS— -${FROM_ADDRESS

  10. #10
    well you can change the username by running the script as a different user. "su - otheruser" But it looks like you are running the server locally... so it'll never go anywhere but on the local host

  11. #11
    Join Date
    Mar 2005
    Location
    Ten1/0/2
    Posts
    2,529
    Quote Originally Posted by usdedi View Post
    i will check it mailx function
    how about the mailx application - and man mailx will help.

    mail and maix are similar, but go with mailx (mail eXtended) it has a few extra features.
    CPanel Shared and Reseller Hosting, OpenVZ VPS Hosting. West Coast (LA) Servers and Nodes
    Running Linux since 1.0.8 Kernel!
    Providing Internet Services since 1995 and Hosting Since 2004

Similar Threads

  1. How to log RSYNC succes/failure in my shell file & send email notification
    By mani_senti in forum Hosting Security and Technology
    Replies: 1
    Last Post: 05-02-2013, 05:02 PM
  2. Capturing shell script output to a variable then send it by email?
    By ninety9 in forum Hosting Security and Technology
    Replies: 5
    Last Post: 08-17-2010, 01:05 PM
  3. Need help modifying shell script to email
    By tnedator in forum Hosting Security and Technology
    Replies: 5
    Last Post: 05-22-2009, 12:38 AM
  4. Help needed on shell script to send mailqueue status.
    By NightMan in forum Programming Discussion
    Replies: 5
    Last Post: 03-03-2007, 05:41 AM
  5. mail script wont send email
    By latheesan in forum Programming Discussion
    Replies: 9
    Last Post: 12-13-2005, 05:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •