• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved Cronjob to import addresses to mailing list

dennis_81

Basic Pleskian
Hello,
I am looking for a way to import a list of eMail addresses into the mailinglist by job.

The mail addresses are in a SQL database. But I have understood so far that there is no direct way to do this.
But I could of course write this list via PHP into a .txt or similar.

Can I import this list automatically by task, e.g. every hour?

I know the solution is somewhere here:

Code:
plesk bin maillist --update MailinglistName -members add:[email protected] -domain example.com

But how do I get Plesk to import content from a text file here, and then how exactly do I run this command via cronjob?

Glad about any hint.

Thank you
Dennis
 
One possible approach could be this:

Create a .txt file that contains all the mail addresses that should be added, example "list.txt":
[email protected]
[email protected]
[email protected]

Then run a small script to import those addresses:
Bash:
for address in `cat list.txt` ; do domain=$(echo $address | sed 's/^\(.*\)@\(.*\)$/\2/') ; plesk bin maillist --update MailinglistName -members add:$address -domain $domain ; done

There are probably more elegant ways to do it but this quick hack should do the job....
 
Hello Monty,

thank you for your answer. Sounds good so far.
I am unfortunately a complete newbie in Plesk. Therefore still a few questions about it:

When I generate the text file, it is in the root of the website. How do I call this text file from the script then?

Can I call your command directly as a cronjob in the Plesk GUI? Or what do I have to do to schedule this script as a task?
 
If we assume that your text file is /var/www/vhosts/example.com/httpdocs/list.txt then:

You could create a bash script /var/www/vhosts/example/import.sh with the content:
Code:
#!/bin/bash

for address in `cat /var/www/vhosts/example.com/httpdocs/list.txt` ; do
    domain=$(echo $address | sed 's/^\(.*\)@\(.*\)$/\2/')
    plesk bin maillist --update MailinglistName -members add:$address -domain $domain
done

Then, make that script executable: chmod +x /var/www/vhosts/example/import.sh

And finally, create a scheduled task in Plesk as root in Tools & Settings -> Scheduled Tasks with the command:
/var/www/vhosts/example/import.sh
 
Hi @Monty


thank you very much for the detailed explanation.
unfortunately it took a moment until i could test it but I think this is how it works.
However, I still have a small permission problem:

If I execute the command directly in SSH terminal with SUDO, it works great.
But if I create a task with my Plesk Administrator, I get the following error:

1643471112431.png


Code:
/var/www/vhosts/mydomain.com/bash/import.sh: line 5: plesk: command not found

My bash script looks like this

Code:
#!/bin/bash

for address in `cat /var/www/vhosts/mydomain.com/httpdocs/list.txt` ; do
    domain=$(echo $address | sed 's/^\(.*\)@\(.*\)$/\2/')
    plesk bin maillist --update testverteiler -members add:$address -domain mydomain.com
done

I suspect this is because I can't access the vhosts subdirectory even with my Plesk Administrator.

But when I try to create and start the task directly with my domain user, I get the same error.

What do I have to change so that this also works as a task?

Thank you very much.

Best regards
Dennis
 
Replace
Bash:
plesk bin maillist --update testverteiler -members add:$address -domain mydomain.com

with
Bash:
/usr/local/psa/bin/maillist --update testverteiler -members add:$address -domain mydomain.com
 
Back
Top