Changeset 417
- Timestamp:
- 09/03/09 17:31:29 (15 years ago)
- Location:
- LATMOS-Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/bin/la-warn-expire
r413 r417 22 22 'm|mail' => \my $mail, 23 23 'help' => sub { pod2usage(0) }, 24 'users|u=s' => \my @users, 25 'to=s' => \my $to, 24 26 ) or pod2usage(); 25 27 … … 32 34 Use this cofngiuration file instead the default one 33 35 34 =item - b|--base basename36 =item -m|mail 35 37 36 Query this specific base instead default. 38 Send a mail to user concerned by the futur expiration of their account 37 39 38 =item -o|object object_type40 =item u|user USER 39 41 40 Query should be performed on this objects. Default is to user 'User' object. 42 Send email only to this user(s) if their account will expire. Usefull for 43 testing and not sending hundred of mail. 41 44 42 =item -e|--empty 45 Multiple users can be specified by using -u several times 43 46 44 Include also unset attributes 47 =item --to MAIL 45 48 46 =item --ro 47 48 Include also read-only attributes as comment 49 Instead sending email to user and eventually their manager, send the mail to 50 only this email address. 49 51 50 52 =back 53 54 =head1 CONFIGURATION 55 56 Some variables are take from configuration file: 57 58 =over 4 59 60 =item mailFrom 61 62 Specify the From address to use in mail 63 64 =item smtp 65 66 The smtp server to use to send mail 67 68 =item alwayscc 69 70 In normal mode (without --to), the mail is also sent this email address. 71 72 =back 73 74 =head1 USERS EMAIL ADDRESSES 75 76 The mail use to send warning to users and manager is taken from 'mail' 77 attributes. If the attributes is unset, the user will not receive the mail. 51 78 52 79 =cut … … 55 82 56 83 if ($mail) { 57 $LA->warn_next_expire_users ;84 $LA->warn_next_expire_users(to => $to, users => (@users ? \@users : undef)); 58 85 } else { 59 86 foreach ($LA->find_next_expire_users()) { -
LATMOS-Accounts/lib/LATMOS/Accounts/Maintenance.pm
r413 r417 40 40 } 41 41 42 =head2 warn_next_expire_users(%options) 43 44 Send a mail to user having account expiring soon 45 46 C<%options are> 47 48 =over 4 49 50 =item users => [] 51 52 Warn only this users (if need) 53 54 =item to 55 56 Send the only to this person. 57 58 =back 59 60 =cut 61 42 62 sub warn_next_expire_users { 43 my ($self ) = @_;63 my ($self, %options) = @_; 44 64 45 65 require Mail::Sendmail; … … 52 72 ); 53 73 foreach my $user ($self->find_next_expire_users) { 74 if ($options{users} && ! grep { $_ eq $user->{name} } @{$options{users}}) { 75 next; 76 } 54 77 my %mail = ( 55 78 From => ($self->val('_default_', 'mailFrom') || … … 69 92 my ($to, @cc) = grep { $_ } ($mail, $managermail, $self->val('_default_', 70 93 'allwayscc')); 71 $mail{to} = 'nanardon@nanardon.zarb.org'; 72 94 if ($options{to}) { 95 $mail{to} = $options{to}; 96 } else { 97 $mail{to} = $to; 98 $mail{cc} = join(', ', @cc); 99 } 100 $mail{to} or next; 73 101 my $message; 74 102 $template->process('account_expire.mail', $user, \$message) 75 103 or die $template->error(); 104 76 105 if (Mail::Sendmail::sendmail( 77 106 %mail, 78 107 Message => $message, 79 108 )) { 80 warn "mail sent to " . ($to || '') . " cc " . (join(', ', @cc) || '') . "\n"; 109 printf("Mail normally set to %s; cc to %s\n", 110 $to, (join(', ', @cc) || '')); 81 111 } else { 82 112 warn $Mail::Sendmail::error
Note: See TracChangeset
for help on using the changeset viewer.