8 Allows scripts to send emails to the development team.
14 package CXGN
::Contact
;
18 use Email
::Send
::SMTP
::Gmail
;
21 use CXGN
::Apache
::Request
;
22 use CXGN
::Tools
::Text
;
29 Desc : Sends an email to the development team.
32 - email address or conf key name that should contain an email
34 - replyto address to include in the email
35 Ret : nothing meaningful
36 Side Effects: dies on error
39 CXGN::Contact::send_email($subject,$body,$mailto);#goes to wherever you say it should go
40 CXGN::Contact::send_email($subject,$body,'email');#goes to email found in conf object
41 CXGN::Contact::send_email($subject,$body,'bugs_email');#goes to bugs_email found in conf object
42 CXGN::Contact::send_email($subject,$body);#goes to this script's default of bugs_email
43 CXGN::Contact::send_email($subject,$body,$mailto,$replyto);#sends an email with a reply-to different from the sender (the sender is the apache user from the conf object, usually www-data)
48 my ( $subject, $body, $mailto, $replyto ) = @_;
49 my $request_info = "";
50 my $vhost_conf = SGN
::Context
->new;
51 my @main_production_site_url = split "\:\/\/", $vhost_conf->get_conf('main_production_site_url');
52 my $hostname = $main_production_site_url[1];
54 #my $dnsdomainname = `dnsdomainname`;
55 #chomp($dnsdomainname);
56 my $mailfrom = $vhost_conf->get_conf('www_user') . '@' . $hostname;
58 #if we are specifying a mailto as a vhost configuration variable (such as 'bugs_email'), then use that variable's value, and append the request info.
59 #mailto can also be specified normally (such as 'John Binns <zombieite@gmail.com>').
60 if ( $mailto and eval{ $vhost_conf->get_conf($mailto)} ) {
61 $mailto = $vhost_conf->get_conf($mailto);
62 ##$request_info .= CXGN::Apache::Request::as_verbose_string();
65 #if we have no one specified to mail to, send it to bugs, and append the request info.
67 $mailto = $vhost_conf->get_conf('bugs_email')
68 ; #for all emails that do not specify email address, send them to our bugs_email
69 ##$request_info .= CXGN::Apache::Request::as_verbose_string()
70 ; #append request info to all emails that do not specify email address
73 $subject ||= 'No subject specified';
74 $body ||= 'No message body specified';
75 $mailto ||= 'sgn-bugs@sgn.cornell.edu';
77 $body .= $request_info;
78 print STDERR
"$subject\n\n$body";
79 #if ( $vhost_conf->get_conf('production_server') ) {
80 if ( $vhost_conf->get_conf('disable_emails') ) {
81 print STDERR
"CXGN::Contact: Configured as production server, but not configured to send emails; no email sent from $mailfrom to $mailto.\n";
84 my $smtp_server = $vhost_conf->get_conf('smtp_server');
85 my $smtp_layer = $vhost_conf->get_conf('smtp_layer');
86 my $smtp_port = $vhost_conf->get_conf('smtp_port');
87 my $smtp_login = $vhost_conf->get_conf('smtp_login');
88 my $smtp_pass = $vhost_conf->get_conf('smtp_pass');
89 my $smtp_auth = $vhost_conf->get_conf('smtp_auth');
90 my $smtp_from = $vhost_conf->get_conf('smtp_from') || $mailfrom;
92 # If SMTP config values are found use external SMTP server
93 if ( $smtp_server and $smtp_login and $smtp_pass ) {
95 my ($mail,$error) = Email
::Send
::SMTP
::Gmail
->new(
96 -smtp
=> $smtp_server,
97 -layer
=> $smtp_layer,
99 -login
=> $smtp_login,
105 print STDERR
"CXGN::Contact: SMTP error: $error\n";
111 -subject
=> $subject,
115 } elsif ( $smtp_server ) {
117 my ($mail,$error) = Email
::Send
::SMTP
::Gmail
->new(
118 -smtp
=> $smtp_server,
119 -layer
=> $smtp_layer,
125 print STDERR
"CXGN::Contact: SMTP error: $error\n";
131 -subject
=> $subject,
143 $mail{'Reply-To'} = $replyto;
145 print STDERR
"MAIL = ".Dumper
(\
%mail);
147 if ( sendmail
(%mail) ) {
148 print STDERR
"CXGN::Contact: Email notification sent from $mailfrom to $mailto.\n";
151 print STDERR
"CXGN::Contact: UNABLE TO SEND EMAIL NOTIFICATION\n";
158 # print STDERR "CXGN::Contact: Not configured as production server; no email sent from $mailfrom to $mailto.\n";
165 john binns - John Binns <zombieite@gmail.com>