PageRenderTime 73ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/CXGN/Contact.pm

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