The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Send mail within bash script with SMTP AUTH

Discussion in 'E-mail Discussions' started by MattiaMerliniM, May 22, 2015.

  1. MattiaMerliniM

    Joined:
    May 22, 2015
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Italy
    cPanel Access Level:
    Root Administrator
    As in the title I need to send email (with log report, etc..) within a bash script executed by a cronjob.
    As I set in my WHM this two things (Mod security):
    1. The pseudo-user “nobody” is not permitted to send email.
    2. Outbound SMTP connections are restricted.
    I can't send email without SMTP authentication (I think).
    I need to authenticate in an external server (onother WHM&cPanel).

    How should I write this bash script?

    Up to now my script is:

    Code:
    #!/bin/bash
    DATA=`date +%H`
    FILE="/home/path/to/file/file.txt"
    USER="domaincom"
    DOMINIO="domain.com"
    TO="myuser@domain1.it"
    FROM="cpanel"
    SUBJECT="email from cP"
    
    echo "To: $TO" >> $FILE
    echo "From: $FROM" >> $FILE
    echo "Subject: $SUBJECT" >> $FILE
    echo " " >> $FILE
    
    cat "/home/$USER/access-logs/$DOMINIO" | grep "/2015:$DATA" >> $FILE
    /usr/sbin/sendmail -t < $FILE
    
    
     
    #1 MattiaMerliniM, May 22, 2015
    Last edited by a moderator: May 22, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,724
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You will likely receive more input on development questions on a website such as StackOverflow. Or, you could try searching for "PHP SMTP Authentication" on a search engine for examples of how others have developed these types of scripts.

    Thank you.
     
    MattiaMerliniM likes this.
Loading...

Share This Page