Internal Newsletter for Dovecot/Roundcube/VimbAdmin

Share your own howto's etc. Not for support questions!

Internal Newsletter for Dovecot/Roundcube/VimbAdmin

Postby skawade » 2016-08-31 07:45

Hi guys,

i am very new to linux/Debian and i asked on for help, how to send a internal e-mail to every registered mailbox in e. g. VimbAdmin.

So i was bored yesterday and i decided trying to make my first own bash script, and here it is:

Code: Select all
#Script to send a message to every mailbox registered in a MySQL database
#Script by Michael Skalda
#There are two ways of running the script:
#Way 1: without parameter: Script will ask you for subject and message content
#Way 2: with parameter: ./ subject messagecontent

#check if parameters are empty
if [ -z "$1" ] && [ -z "$2" ]
#if both are empty, subject and messagecontent will be requested per read -p
echo 'Send a mail to every user in your Mail-Database!'
read -p "Subject: " subject
echo 'HTML is activated! example: wordwrap <br>, paragraph with <p>'
read -p "Message: " message
#if there is at least one parameter given, it will check if $2 is empty
elif [ -z "$2" ]
#if $2 is empty, user will be prompt to write the message, again with read -p
echo 'Subject: ' $subject
echo 'HTML is activated! example: wordwrap <br>, paragraph with <p>'
read -p "Message: " message
#when both parameters are given, the mail will be instantly sent
echo 'Subject: ' $subject
echo 'Message: ' $message
echo 'Sending E-Mail...'
#MySQL-User with access to your mailbox database

#MySQL-User's password

#your mailbox database (e.g. vimbadmin)

#set the sender name/mailbox

#read the sql entrys of the column "mailbox" and saves it to the array "emails". The column name is skipped, cause otherwise it will try to send an mail to "mailbox"
while read line
done < <(mysql --skip-column-names -u${sql_user} -p${sql_psw} ${sql_database} -e "SELECT username FROM mailbox")

#send the e-mail with the just gathered data
echo "$message" | mailx -a 'Content-Type: text/html' -a "From: $postmaster" -s "$subject" ${emails[@]}
echo 'Success! Mail was sent to the following mailboxes:'
for i in ${emails[@]}; do
 echo $i

Would like to hear your opinions and any suggestions, i want to learn scripting and linux as good as i can :P

Thank you :))
Posts: 1
Joined: 2016-08-31 07:15

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 6 guests