ProductOpener::Mail - sends emails to admin and producers. Moreover, replies to user queries.
ProductOpener::Mail
is used to send emails from the contact address of the Open Food Facts to users,
admin,
and producers.
use ProductOpener::Mail qw/:all/; $contact_email = 'contact@openbeautyfacts.org'; $admin_email = 'stephane@openfoodfacts.org'; $producers_email = 'producers@openfoodfacts.org';
The module implements the sending of emails from the Open Food Facts contact email address to users, admin, and producers. These emails can be used to reply to user queries, submit feedback, or to request access from admin and producers.
Text used before logging an email
Text used after logging an email
Secure way to send an email (private method)
Depending on $log_emails configuration it might just log the email instead of sending it.
Errors are logged.
The email should be ready to be send
send_email()
sends a plain text email from the contact email of Open Food Facts to the email passed as an argument.
The first argument is a hash reference. The other two arguments are scalar variables that consist of email subject and body.
The hash must contain values for the following keys:
- email -> user email - name -> user name
The function returns a 1 or 0 depending on the evaluation of the email sent or not.
If the function catches any error during evaluation it returns 1 indicating an error. On the other hand, if there was no error, it returns 0 indicating that the email has been sent successfully.
send_html_email()
sends an HTML email from the contact email of Open Food Facts to the email passed as an argument.
The first argument is a hash reference. The other two arguments are scalar variables that consist of email subject and HTML content.
The hash must contain values for the following keys:
- email -> user email - name -> user name
The function returns a 1 or 0 depending on the evaluation of the email sent or not.
If the function catches any error during evaluation it returns 1 indicating an error. On the other hand, if there was no error, it returns 0 indicating that the email has been sent successfully.
Fetch the HTML email content in $BASE_DIRS{LANG}/emails. If a translation is available for the requested language, we provide the translated version otherwise English is the default.
The HTML file name (ex: user_welcome.html)
The 2-letter language code
The HTML string or undef if the file does not exists or is not readable.
send_email_to_admin()
sends email from the contact email of Open Food Facts to the admin.
Two scalar variables that contain the email subject and body are passed as an argument.
The function returns a 1 or 0 depending on the evaluation of the email sent or not.
If the function catches any error during evaluation it returns 1 indicating an error. On the other hand, if there was no error, it returns 0 indicating that the email has been sent successfully.
send_email_to_producers_admin()
sends email from the contact email of Open Food Facts to producers admin.
Two scalar variables that contain the email subject and body are passed as an argument.
The function returns a 1 or 0 depending on the evaluation of email sent or not.
If the function catches any error during evaluation it returns 1 indicating an error. On the other hand, if there was no error, it returns 1 indicating that email has sent successfully.