Merge branch 'master' into topic/analyze_phenotypes_page
[sgn.git] / lib / CXGN / Contact.pm
blobe0aad0367aafc1845f46850ef7ce70f39cccbe14
2 =head1 NAME
4 CXGN::Contact
6 =head1 DESCRIPTION
8 Allows scripts to send emails to the development team.
10 =head1 FUNCTIONS
12 =cut
14 package CXGN::Contact;
15 use strict;
17 use Mail::Sendmail;
19 use CXGN::Apache::Request;
20 use CXGN::Tools::Text;
22 use SGN::Context;
24 =head2 send_email
26 Usage:
27 Desc : Sends an email to the development team.
28 Args : - subject,
29 - message body,
30 - email address or conf key name that should contain an email
31 address to send to
32 - replyto address to include in the email
33 Ret : nothing meaningful
34 Side Effects: dies on error
35 Example:
37 CXGN::Contact::send_email($subject,$body,$mailto);#goes to wherever you say it should go
38 CXGN::Contact::send_email($subject,$body,'email');#goes to email found in conf object
39 CXGN::Contact::send_email($subject,$body,'bugs_email');#goes to bugs_email found in conf object
40 CXGN::Contact::send_email($subject,$body);#goes to this script's default of bugs_email
41 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)
43 =cut
45 sub send_email {
46 my ( $subject, $body, $mailto, $replyto ) = @_;
47 my $request_info = "";
48 my $vhost_conf = SGN::Context->new;
49 my $hostname = `hostname`;
50 chomp($hostname);
51 #my $dnsdomainname = `dnsdomainname`;
52 #chomp($dnsdomainname);
53 my $mailfrom = $vhost_conf->get_conf('www_user') . '@' . $hostname;
55 #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.
56 #mailto can also be specified normally (such as 'John Binns <zombieite@gmail.com>').
57 if ( $mailto and eval{ $vhost_conf->get_conf($mailto)} ) {
58 $mailto = $vhost_conf->get_conf($mailto);
59 ##$request_info .= CXGN::Apache::Request::as_verbose_string();
62 #if we have no one specified to mail to, send it to bugs, and append the request info.
63 unless ($mailto) {
64 $mailto = $vhost_conf->get_conf('bugs_email')
65 ; #for all emails that do not specify email address, send them to our bugs_email
66 ##$request_info .= CXGN::Apache::Request::as_verbose_string()
67 ; #append request info to all emails that do not specify email address
70 $subject ||= 'No subject specified';
71 $body ||= 'No message body specified';
72 $mailto ||= 'sgn-bugs@sgn.cornell.edu';
74 $body .= $request_info;
75 print STDERR "$subject\n\n$body";
76 if ( $vhost_conf->get_conf('production_server') ) {
77 if ( $vhost_conf->get_conf('disable_emails') ) {
78 print STDERR
79 "CXGN::Contact: Configured as production server, but not configured to send emails; no email sent from $mailfrom to $mailto.\n";
81 else {
82 my %mail = (
83 To => $mailto,
84 From => $mailfrom,
85 Subject => $subject,
86 Body => $body,
88 $mail{'Reply-To'} = $replyto;
89 if ( sendmail(%mail) ) {
90 print STDERR
91 "CXGN::Contact: Email notification sent from $mailfrom to $mailto.\n";
93 else {
94 print STDERR "CXGN::Contact: UNABLE TO SEND EMAIL NOTIFICATION\n";
98 else {
99 print STDERR
100 "CXGN::Contact: Not configured as production server; no email sent from $mailfrom to $mailto.\n";
105 =head1 AUTHOR
107 john binns - John Binns <zombieite@gmail.com>
109 =cut
112 1;#do not remove