Odyssey
Public Member Functions | Public Attributes | Private Member Functions | List of all members
ErrorMail Class Reference

Public Member Functions

 SendMail ()
 
 SendErr ()
 

Public Attributes

 $logmode
 
 $logfile
 
 $header
 
 $mailcmd
 
 $mailto
 
 $mailfrom
 
 $mailfromname
 
 $replyto
 
 $script
 
 $subject
 
 $msgbody
 
 $line
 
 $file
 
 $callingfunction
 
 $physfile
 
 $error
 
 $server_id
 
 $sql
 
 $errdate
 
 $cu
 
 $member
 

Private Member Functions

 getPyFileLocation ()
 
 getAwsSesLoggingContextJsonString ()
 

Detailed Description

Definition at line 9 of file errormail.i.

Member Function Documentation

◆ getAwsSesLoggingContextJsonString()

ErrorMail::getAwsSesLoggingContextJsonString ( )
private

Prepare a a dictionary of {context: "json ob"} –context option for Python Email Sending Script

Definition at line 84 of file errormail.i.

84  {
85 
86  $context = array();
87 
88  // these attributes are expected to be set on the calling
89  // side before invoking SendMail and SendErr
90  $context["cucode"] = $this->cu;
91  $context["callingScript"] = $this->file;
92  $context["callingFunction"] = $this->callingfunction;
93  $context["serverName"] = $this->server;
94  $context["ServerScript"] = $this->script;
95 
96  return HCU_JsonEncode($context);
97  }

◆ getPyFileLocation()

ErrorMail::getPyFileLocation ( )
private

Obtain a python file that will send the email.

Definition at line 70 of file errormail.i.

70  {
71  # Goal is to default it with a script with more generalized functionality
72  # added in sendSESEmailBulk.py script
73  if ($this->bulk) {
74  return dirname(__FILE__) . "/../scripts/sendSESEmailBulk.py";
75  } else {
76  return dirname(__FILE__) . "/../scripts/sendSESEmail.py";
77  }
78  }

◆ SendErr()

ErrorMail::SendErr ( )

function SendErr() This sends an email pointing out an error. At this point in time, all references in Odyssey have not been updated. No, this is not the email in Mammoth which comes from the error handler.

Definition at line 184 of file errormail.i.

184  {
185  $pyFile = $this->pyFile;
186 
187  $msg = "";
188  $msg .= "Error in $this->script on Server $this->server\\n";
189  $msg .= "Called as $this->query\\n\\n";
190  $msg .= $this->line == "" ? "" : "LINE: $this->line\\n";
191  $msg .= $this->file == "" ? "" : "FILE: $this->file\\n";
192  $msg .= $this->error == "" ? "" : "ERROR: $this->error\\n";
193  $msg .= $this->sql == "" ? "" : "SQL: $this->sql\\n";
194  $msg .= $this->cu == "" ? "" : "CU: $this->cu\\n";
195  $msg .= $this->member == "" ? "" : "MEMBER: $this->member\\n";
196 
197  // Set up message
198  // Requires some finagling: if newline is literal \n then bash line doesn't work but with \\n, it shows up in the email as "\n."
199  $plainTextString = "--plaintext \"`echo " . escapeshellarg($msg) . "`\"";
200 
201  // Set up subject
202  $subject = "Error in $this->script";
203  $subjectString = "--subject " . escapeshellarg($subject);
204 
205  // Set up from
206  $fromString = "--efrom " . escapeshellarg($this->mailfrom);
207 
208  // Set up to. Amazon has a limit of 50 recipients so parse at this point.
209  $toArray = is_array($this->mailto) ? $this->mailto : explode(";", str_replace(",", ";", strval($this->mailto)));
210  $toSwitch = $this->hideto ? "--bcc" : "--to";
211  $toList = array();
212 
213  $awsSesLoggingContext = "--context " . escapeshellarg($this->getAwsSesLoggingContextJsonString());
214 
215  foreach($toArray as $toEmail) {
216  if (trim($toEmail) != "") {
217  $toList[] = escapeshellarg($toEmail);
218 
219  if (count($toList) >= 50) {
220  $toString = "$toSwitch " . implode(" ", $toList);
221  $cmd = "(python3 $pyFile $toString $fromString $subjectString $plainTextString $awsSesLoggingContext) &";
222  exec($cmd);
223  $toList = array();
224  }
225  }
226  }
227 
228  $toString = "$toSwitch " . implode(" ", $toList);
229  $cmd = "(python3 $pyFile $toString $fromString $subjectString $plainTextString $awsSesLoggingContext) &";
230  exec($cmd);
231  }
getAwsSesLoggingContextJsonString()
Definition: errormail.i:84

◆ SendMail()

ErrorMail::SendMail ( )

function SendMail() Send an email through AWS SES. Like the previous implemention, the email is sent in the background. That means that there is no checking to see if the email has failed. For AWS SES fails are: 1) Invalid syntax of either from or to emails (should be checked before), 2) The From email is not verified (at this point in time, the default of norep.nosp@m.ly@h.nosp@m.omecu.nosp@m..net is not verified.), For more information,

See also
the sendSESEmail.py script.

Definition at line 111 of file errormail.i.

111  {
112  $pyFile = $this->getPyFileLocation();
113 
114  // Set up from
115  $from = $this->mailfromname != '' ? "{$this->mailfromname} <{$this->mailfrom}>" : $this->mailfrom;
116  $fromString = "--efrom " . escapeshellarg($from);
117 
118  // Set up reply to
119  $replyToString = $this->replyto != "" ? "--replyto " . escapeshellarg($this->replyto) : "";
120 
121  // Set up subject
122  $subjectString = "--subject " . escapeshellarg($this->subject);
123 
124  // Now HTML emails are set up using the header declaration (legacy).
125  // Also allow direct setting of the plaintext and htmltext parts of the email.
126  $plainTextBody = "";
127  $htmlTextBody = "";
128  if ($this->htmlMsgbody != "") {
129  $htmlTextBody = $this->htmlMsgbody;
130  }
131  if ($this->plainMsgbody != "") {
132  $plainTextBody = $this->plainMsgbody;
133  }
134  if ($this->msgbody != "") {
135  if (trim(strtolower($this->header)) == "content-type: text/html") { // For the most part, they have the same case except for a couple.
136  $htmlTextBody = $this->msgbody;
137  } else {
138  $plainTextBody = $this->msgbody;
139  }
140  }
141 
142  // Need to escape newlines. They cause the email to fail.
143  $plainTextString = "";
144  $htmlTextString = "";
145  if ($plainTextBody != "") {
146  // Requires some finagling: if newline is literal \n then bash line doesn't work but with \\n, it shows up in the email as "\n."
147  $plainTextBody = str_replace("\n", "\\n", str_replace("\r\n", "\\r\\n", $plainTextBody));
148  $plainTextString = "--plaintext \"`echo " . escapeshellarg($plainTextBody) . "`\"";
149  }
150  if ($htmlTextBody != "") {
151  // Do not replace newlines with breaks. Script is responsible for displaying correctly; also breaks image data (in the case of billing/workflow emails.)
152  $htmlTextString = "--htmltext " . escapeshellarg($htmlTextBody);
153  }
154 
155  if ($plainTextString == "" && $htmlTextString == "") {
156  $plainTextString = "--plaintext ''";
157  }
158 
159  // Set up to. Amazon has a limit of 50 recipients so parse at this point.
160  $toArray = is_array($this->mailto) ? $this->mailto : explode(";", str_replace(",", ";", strval($this->mailto)));
161  $toSwitch = $this->hideto ? "--bcc" : "--to";
162  $executeQuietly = $this->executeQuietly ? "--quiet" : "";
163 
164  // sanitize list of emails
165  $toArray = array_map("trim", $toArray);
166  $toArray = array_map("escapeshellarg", $toArray);
167 
168  $toString = "$toSwitch " . implode(" ", $toArray);
169 
170  $awsSesLoggingContext = "--context " . escapeshellarg($this->getAwsSesLoggingContextJsonString());
171 
172  $cmd = "(python3 $pyFile $toString $fromString $subjectString $plainTextString \
173  $htmlTextString $replyToString $executeQuietly $awsSesLoggingContext) > /dev/null &";
174 
175  exec($cmd);
176  }
getAwsSesLoggingContextJsonString()
Definition: errormail.i:84
getPyFileLocation()
Definition: errormail.i:70

The documentation for this class was generated from the following file: