8 Allows scripts to send emails to the development team.
14 package CXGN
::Contact
;
18 use Email
::Send
::SMTP
::Gmail
;
20 use CXGN
::Apache
::Request
;
21 use CXGN
::Tools
::Text
;
28 Desc : Sends an email to the development team.
31 - email address or conf key name that should contain an email
33 - replyto address to include in the email
34 Ret : nothing meaningful
35 Side Effects: dies on error
38 CXGN::Contact::send_email($subject,$body,$mailto);#goes to wherever you say it should go
39 CXGN::Contact::send_email($subject,$body,'email');#goes to email found in conf object
40 CXGN::Contact::send_email($subject,$body,'bugs_email');#goes to bugs_email found in conf object
41 CXGN::Contact::send_email($subject,$body);#goes to this script's default of bugs_email
42 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)
47 my ( $subject, $body, $mailto, $replyto ) = @_;
48 my $request_info = "";
49 my $vhost_conf = SGN
::Context
->new;
50 my @main_production_site_url = split "\:\/\/", $vhost_conf->get_conf('main_production_site_url');
51 my $hostname = $main_production_site_url[1];
53 #my $dnsdomainname = `dnsdomainname`;
54 #chomp($dnsdomainname);
55 my $mailfrom = $vhost_conf->get_conf('www_user') . '@' . $hostname;
57 #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.
58 #mailto can also be specified normally (such as 'John Binns <zombieite@gmail.com>').
59 if ( $mailto and eval{ $vhost_conf->get_conf($mailto)} ) {
60 $mailto = $vhost_conf->get_conf($mailto);
61 ##$request_info .= CXGN::Apache::Request::as_verbose_string();
64 #if we have no one specified to mail to, send it to bugs, and append the request info.
66 $mailto = $vhost_conf->get_conf('bugs_email')
67 ; #for all emails that do not specify email address, send them to our bugs_email
68 ##$request_info .= CXGN::Apache::Request::as_verbose_string()
69 ; #append request info to all emails that do not specify email address
72 $subject ||= 'No subject specified';
73 $body ||= 'No message body specified';
74 $mailto ||= 'sgn-bugs@sgn.cornell.edu';
76 $body .= $request_info;
77 print STDERR
"$subject\n\n$body";
78 if ( $vhost_conf->get_conf('production_server') ) {
79 if ( $vhost_conf->get_conf('disable_emails') ) {
80 print STDERR
"CXGN::Contact: Configured as production server, but not configured to send emails; no email sent from $mailfrom to $mailto.\n";
83 my $smtp_server = $vhost_conf->get_conf('smtp_server');
84 my $smtp_layer = $vhost_conf->get_conf('smtp_layer');
85 my $smtp_port = $vhost_conf->get_conf('smtp_port');
86 my $smtp_login = $vhost_conf->get_conf('smtp_login');
87 my $smtp_pass = $vhost_conf->get_conf('smtp_pass');
88 my $smtp_auth = $vhost_conf->get_conf('smtp_auth');
89 my $smtp_from = $vhost_conf->get_conf('smtp_from') || $mailfrom;
91 # If SMTP config values are found use external SMTP server
92 if ( $smtp_server and $smtp_login and $smtp_pass ) {
94 my ($mail,$error) = Email
::Send
::SMTP
::Gmail
->new(
95 -smtp
=> $smtp_server,
96 -layer
=> $smtp_layer,
98 -login
=> $smtp_login,
104 print STDERR
"CXGN::Contact: SMTP error: $error\n";
110 -subject
=> $subject,
122 $mail{'Reply-To'} = $replyto;
124 if ( sendmail
(%mail) ) {
125 print STDERR
"CXGN::Contact: Email notification sent from $mailfrom to $mailto.\n";
128 print STDERR
"CXGN::Contact: UNABLE TO SEND EMAIL NOTIFICATION\n";
135 print STDERR
"CXGN::Contact: Not configured as production server; no email sent from $mailfrom to $mailto.\n";
142 john binns - John Binns <zombieite@gmail.com>