Re: Email all local accounts?

"Fred" <[email protected]> Fri, 18 Nov 2011 15:47:49 -0500
Newsgroups gmane.mail.xmail.general
Message-ID <014501cca633$55d9ecf0$018dc6d0$@com>
Hi,

Thanks for your reply, here is what I have come up with if someone else is
interested.

#!/usr/local/bin/php
<?php

function xmail_accounts_list($tabfile)
{
	$accounts = array();
	$lines = file($tabfile);
	foreach ($lines as $line_num => $line)
	{
		$data = explode("\t", $line);
		$accounts[] = substr($data[1], 1, -1) . "@" .
substr($data[0], 1, -1);
	}
	return $accounts;
}

function send_maintenance_mail($account)
{
	$to = strtolower($account);
	$from = "[email protected]";
	$current_date = date("Y-m-d G:i:s");
	$subject = "Your subject";
	
	$mime_boundary = "----mail.yourdomain.com----" . md5(time());

	$headers = "From: [email protected]
<[email protected] >\n";
	$headers .= "Reply-To: [email protected], " . $to . "\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-Type: multipart/alternative; boundary=\"" .
$mime_boundary . "\"\n";

	$message = "--" . $mime_boundary . "\n";
	$message .= "Content-Type: text/html; charset=UTF-8\n";
	$message .= "Content-Transfer-Encoding: 8bit\n\n";

	$message .= "<html>\n";
	$message .= "<body>\n";
	$message .= "Your message. \n";
	$message .= "</body>\n";
	$message .= "</html>\n";

	$message .= "--" . $mime_boundary . "--\n\n";

	if(mail($to, $subject, $message, $headers))
	{
		return true;
	}
	else
	{
		return false;
	}
}

$accounts = xmail_accounts_list("/mailsrv/MailRoot/mailusers.tab");

foreach ($accounts as $account_num => $account)
{
	if(!send_maintenance_mail($account))
	{
		echo "Error sending mail to " . $account;
		exit;
	}
}

echo "Email sent to " . count($accounts) . " accounts.\n";

exit;

?>


From: [email protected] [mailto:[email protected]]
On Behalf Of Ivo Smits
Sent: 18 novembre 2011 11:07
To: [email protected]
Subject: Re: [xmail] Email all local accounts?

Hi,

I don't think this is directly supported. You can generate a list of e-mail
addresses from the mailusers file, for example using this command on linux:
cat mailusers.tab | sed -n 's/^"\([^"]*\)"\t"\([^"]*\)"\t.*$/\2@\1/p'

You could write the output to a file and pass it to sendmail using the
--rcpt-file option.

--
Ivo

Op 18-11-2011 16:37, Fred schreef: 
Hey guys,
 
Quick question; is there a way to broadcast an email to all XMail accounts
on a  single server?
 
I need to inform everyone, about 800 accounts, that I will do hardware
maintenance this week-end.
 
Thanks 
 
 



_______________________________________________
xmail mailing list
[email protected]
http://xmailserver.org/mailman/listinfo/xmail

_______________________________________________
xmail mailing list
[email protected]
http://xmailserver.org/mailman/listinfo/xmail