Enable WebGUI sites to send SMS messages as inbox notifications.
This commit is contained in:
commit
f54e975c14
8 changed files with 303 additions and 18 deletions
|
|
@ -267,16 +267,28 @@ A unique id for this message, in case you want to see what replies come in for i
|
|||
|
||||
If this is a reply to a previous message, then you should specify the messageId of the previous message here.
|
||||
|
||||
=head3 isInbox
|
||||
|
||||
A flag indicating that this email message is from the Inbox, and should follow per user settings
|
||||
for delivery.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $headers = shift;
|
||||
my $isInbox = shift;
|
||||
if ($headers->{toUser}) {
|
||||
my $user = WebGUI::User->new($session, $headers->{toUser});
|
||||
if (defined $user) {
|
||||
my $email = $user->profileField("email");
|
||||
my $email;
|
||||
if ($isInbox) {
|
||||
$email = $user->getInboxAddresses;
|
||||
}
|
||||
else {
|
||||
$email = $user->profileField("email");
|
||||
}
|
||||
if ($email) {
|
||||
if ($headers->{to}) {
|
||||
$headers->{to} .= ','.$email;
|
||||
|
|
@ -286,9 +298,9 @@ sub create {
|
|||
}
|
||||
}
|
||||
}
|
||||
my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">";
|
||||
my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">";
|
||||
my $type = $headers->{contentType} || "multipart/mixed";
|
||||
my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath");
|
||||
my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath");
|
||||
|
||||
# format of Message-Id should be '<unique-id@domain>'
|
||||
my $id = $headers->{messageId} || "WebGUI-" . $session->id->generate;
|
||||
|
|
@ -326,7 +338,7 @@ sub create {
|
|||
delete $headers->{toGroup};
|
||||
$message->attach(Data=>"This message was intended for ".$to." but was overridden in the config file.\n\n");
|
||||
}
|
||||
bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup} }, $class;
|
||||
bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup}, _isInbox => $isInbox }, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -469,10 +481,10 @@ sub send {
|
|||
else {
|
||||
my $smtp = Net::SMTP->new($smtpServer); # connect to an SMTP server
|
||||
if (defined $smtp) {
|
||||
$smtp->mail($mail->head->get("X-Return-Path"));
|
||||
$smtp->to(split(",",$mail->head->get("to")));
|
||||
$smtp->cc(split(",",$mail->head->get("cc")));
|
||||
$smtp->bcc(split(",",$mail->head->get("bcc")));
|
||||
$smtp->mail($mail->head->get('X-Return-Path'));
|
||||
$smtp->to( split(',', $mail->head->get('to') ));
|
||||
$smtp->cc( split(',', $mail->head->get('cc') ));
|
||||
$smtp->bcc( split(',', $mail->head->get('bcc') ));
|
||||
$smtp->data(); # Start the mail
|
||||
$smtp->datasend($mail->stringify);
|
||||
$smtp->dataend(); # Finish sending the mail
|
||||
|
|
@ -492,15 +504,21 @@ sub send {
|
|||
if ($group) {
|
||||
my $group = WebGUI::Group->new($self->session, $group);
|
||||
return $status if !defined $group;
|
||||
$mail->head->replace("bcc", undef);
|
||||
$mail->head->replace("cc", undef);
|
||||
foreach my $userId (@{$group->getAllUsers(1)}) {
|
||||
$mail->head->replace('bcc', undef);
|
||||
$mail->head->replace('cc', undef);
|
||||
USER: foreach my $userId (@{$group->getAllUsers(1)}) {
|
||||
my $user = WebGUI::User->new($self->session, $userId);
|
||||
next unless $user->status eq 'Active'; ##Don't send this to invalid user accounts
|
||||
if ($user->profileField("email")) {
|
||||
$mail->head->replace("To",$user->profileField("email"));
|
||||
$self->queue;
|
||||
next USER unless $user->status eq 'Active'; ##Don't send this to invalid user accounts
|
||||
my $emailAddress;
|
||||
if ($self->{_isInbox}) {
|
||||
$emailAddress = $user->getInboxAddresses;
|
||||
}
|
||||
else {
|
||||
$emailAddress = $user->profileField('email');
|
||||
}
|
||||
next USER unless $emailAddress;
|
||||
$mail->head->replace('To', $emailAddress);
|
||||
$self->queue;
|
||||
}
|
||||
#Delete the group if it is flagged as an AdHocMailGroup
|
||||
$group->delete if ($group->isAdHocMailGroup);
|
||||
|
|
|
|||
|
|
@ -295,6 +295,14 @@ sub definition {
|
|||
hoverHelp=>$i18n->get('mail return path help'),
|
||||
defaultValue=>$setting->get("mailReturnPath")
|
||||
});
|
||||
push(@fields, {
|
||||
tab => 'messaging',
|
||||
fieldType => 'email',
|
||||
name => 'smsGateway',
|
||||
label => $i18n->get('sms gateway'),
|
||||
hoverHelp => $i18n->get('sms gateway help'),
|
||||
defaultValue => $setting->get('smsGateway'),
|
||||
});
|
||||
# misc
|
||||
push(@fields, {
|
||||
tab=>"misc",
|
||||
|
|
|
|||
|
|
@ -504,6 +504,34 @@ sub getGroupIdsRecursive {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getInboxAddresses ( )
|
||||
|
||||
Return a string with addresses that the user wants to receive Inbox
|
||||
notifications. If the user does not want Inbox notifications, then
|
||||
the string will be empty.
|
||||
|
||||
=cut
|
||||
|
||||
sub getInboxAddresses {
|
||||
my $self = shift;
|
||||
my $emails = '';
|
||||
if ( $self->profileField('receiveInboxEmailNotifications')
|
||||
&& $self->profileField('email')) {
|
||||
$emails = $self->profileField('email');
|
||||
}
|
||||
if ( $self->profileField('receiveInboxSmsNotifications')
|
||||
&& $self->profileField('cellPhone')
|
||||
&& $self->session->setting->get('smsGateway')) {
|
||||
$emails .= ',' if $emails;
|
||||
my $phoneNumber = $self->profileField('cellPhone');
|
||||
$phoneNumber =~ tr/0-9//dc; ##remove nonnumbers
|
||||
$emails = join '', $emails, $phoneNumber, '@', $self->session->setting->get('smsGateway');
|
||||
}
|
||||
return $emails;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getProfileFieldPrivacySetting ( [field ])
|
||||
|
||||
Returns the privacy setting for the field passed in. If no field is passed in the entire hash is returned
|
||||
|
|
|
|||
|
|
@ -4359,12 +4359,13 @@ Users may override this setting in their profile.
|
|||
'recaptcha public key' => {
|
||||
message => 'reCAPTCHA Public Key'
|
||||
},
|
||||
|
||||
'Ad Space control name' => {
|
||||
message => q|Ad Space|,
|
||||
lastUpdated => 0,
|
||||
context => q|name for the Ad Space control|
|
||||
},
|
||||
|
||||
|
||||
'global head tags label' => {
|
||||
message => 'Global Head Tags',
|
||||
lastUpdated => 0,
|
||||
|
|
@ -4376,6 +4377,17 @@ Users may override this setting in their profile.
|
|||
context => 'Description of setting',
|
||||
},
|
||||
|
||||
'sms gateway' => {
|
||||
message => q|SMS gateway|,
|
||||
context => q|email to SMS/text email address for this site.|,
|
||||
lastUpdated => 1235685248,
|
||||
},
|
||||
|
||||
'sms gateway help' => {
|
||||
message => q|The email address that this site would use to send an SMS message.|,
|
||||
lastUpdated => 1235695517,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue