Can't setup custom email using sendgrid instead of inbuilt phpmailer?

OJS 3.2.1.1

I am trying to enable SMTP emails using sendgrid api but I am receiving the same error every time when trying to send emails.

The email configuration of my config.inc.php looks like this, any suggestion?

    ;;;;;;;;;;;;;;;;;;
    ; Email Settings ;
   ;;;;;;;;;;;;;;;;;;
    
    [email]

   ; Use SMTP for sending mail instead of mail()
   smtp = On

   ; SMTP server settings
   smtp_server = "ssl://smtp.sendgrid.net"
   smtp_port = 465

   ; Enable SMTP authentication
   ; Supported mechanisms: ssl, tls
   smtp_auth = ssl
   smtp_username = "apikey"
   smtp_password = "xyz"

   ; Enable suppressing verification of SMTP certificate in PHPMailer
   ; Note: this is not recommended per PHPMailer documentation
   ; smtp_suppress_cert_check = Off

   ; Allow envelope sender to be specified
   ; (may not be possible with some server configurations)
   ; allow_envelope_sender = Off

   ; Default envelope sender to use if none is specified elsewhere
   ; default_envelope_sender = ""

   ; Force the default envelope sender (if present)
   ; This is useful if setting up a site-wide no-reply address
   ; The reply-to field will be set with the reply-to or from address.
   ; force_default_envelope_sender = Off

   ; Force a DMARC compliant from header (RFC5322.From)
   ; If any of your users have email addresses in domains not under your control
   ; you may need to set this to be compliant with DMARC policies published by
   ; those 3rd party domains.
   ; Setting this will move the users address into the reply-to field and the
   ; from field wil be rewritten with the default_envelope_sender.
   ; To use this you must set force_default_enveloper_sender = On and
   ; default_envelope_sender must be set to a valid address in a domain you own.
   ; force_dmarc_compliant_from = Off

   ; The display name to use with a DMARC compliant from header
   ; By default the DMARC compliant from will have an empty name but this can
   ; be changed by adding a text here.
   ; You can use '%n' to insert the users name from the original from header
   ; and '%s' to insert the localized sitename.
   ; dmarc_compliant_from_displayname = '%n via %s'

   ; Amount of time required between attempts to send non-editorial emails
   ; in seconds. This can be used to help prevent email relaying via OJS.
   time_between_emails = 3600

   ; Maximum number of recipients that can be included in a single email
   ; (either as To:, Cc:, or Bcc: addresses) for a non-privileged user
   max_recipients = 10

   ; If enabled, email addresses must be validated before login is possible.
   require_validation = Off

   ; Maximum number of days before an unvalidated account expires and is deleted
   validation_timeout = 14

Capture

Hello all!

I am having exactly the same problem, i have set a sendgrid account (according to sendgrid all domain CNAME records are correctly set) and i am hosting a OJS site on infinityfree (https://infinityfree.net/)

Here is my email configuration:

smtp = On
smtp_server = smtp.sendgrid.net
smtp_port = 587
smtp_auth = tls
smtp_username = apikey
smtp_password = PASSWORD
; allow_envelope_sender = On
; default_envelope_sender = my_address@my_host.com
; force_default_envelope_sender = On
; force_dmarc_compliant_from = Off
time_between_emails = 3600
max_recipients = 10
require_validation = Off
validation_timeout = 14

I only get the “There was a problem sending an email message. Please try again later, or contact your system administrator.” which does not offer any information about the real problem, i have requested access to the PHP logs to dig in a little, but i wanted to ask how problems like these could be investigated… is there a way of making OJS more verbose when it comes to errors? maybe there is somewhere in the database where email sending errors are stored? is there any way of debugging the page? (a request, a js variable, etc…)

Thanks in advance!
Rafael

I was able to fix it at last!

By setting the PHPMailer smtp debug level to level 2 i found out that the “from” address was not a valid sender identity according to sendgrid, this configuration solved it:

smtp = On
smtp_server = smtp.sendgrid.net
smtp_port = 587
smtp_auth = tls
smtp_username = apikey
smtp_password = PASSWORD
allow_envelope_sender = On
default_envelope_sender = info@MYDOMAIN
force_default_envelope_sender = On
force_dmarc_compliant_from = On
dmarc_compliant_from_displayname = ‘%n’
time_between_emails = 3600
max_recipients = 10
require_validation = Off
validation_timeout = 14

PS: After setting the PHPMailer to debug level 2 i was able to catch sendgrid’s response in the browser’s “developer tools” with all the necessary data to debug the problem (basically it contained the dialog between the smtp client and server)

1 Like

Dear @raphael Thanks for your contribution, I will check if these settings works for me too and will back to you soon.

Dear @raphael The settings worked for me too. Thank you very much for the solution. I am grateful. :grinning: :grinning: :pray: :pray: :pray:

Awesome @Pankaj_Kumar! Glad i could help ^^

Dear @raphael can you please look into this issue too? Url .htaccess error when installing Wordpress (myjournal.com) and OJS (myjournal.com/journal) on same domain? - #2 by asmecher
Thanks in advance.

Hi, can you help me?
What was the correct configuration for sendgrid?
i have this but it does not work
smtp = On
smtp_server = smtp.sendgrid.net
smtp_port = 587
smtp_auth = tls
smtp_username = apikey (do not move)
smtp_password = apikey (possible password removed)
allow_envelope_sender = On
default_envelope_sender = my account
force_default_envelope_sender = On
force_dmarc_compliant_from = On
dmarc_compliant_from_displayname = ‘%n’
time_between_emails = 3600
max_recipients = 10
require_validation = Off
validation_timeout = 14

@dios98
Use this code:

Use SMTP for sending mail instead of mail()
smtp = On

SMTP server settings
smtp_server = smtp.sendgrid.net
smtp_port = 587

Enable SMTP authentication
Supported mechanisms: ssl, tls
smtp_auth = tls
smtp_username = apikey
smtp_password = pass

Enable suppressing verification of SMTP certificate in PHPMailer
Note: this is not recommended per PHPMailer documentation
smtp_suppress_cert_check = On

; Allow envelope sender to be specified
; (may not be possible with some server configurations)
allow_envelope_sender = On

; Default envelope sender to use if none is specified elsewhere
default_envelope_sender = youremail@domain.com

; Force the default envelope sender (if present)
; This is useful if setting up a site-wide no-reply address
; The reply-to field will be set with the reply-to or from address.
force_default_envelope_sender = On

; Force a DMARC compliant from header (RFC5322.From)
; If any of your users have email addresses in domains not under your control
; you may need to set this to be compliant with DMARC policies published by
; those 3rd party domains.
; Setting this will move the users address into the reply-to field and the
; from field wil be rewritten with the default_envelope_sender.
; To use this you must set force_default_enveloper_sender = On and
; default_envelope_sender must be set to a valid address in a domain you own.
force_dmarc_compliant_from = On

; The display name to use with a DMARC compliant from header
; By default the DMARC compliant from will have an empty name but this can
; be changed by adding a text here.
; You can use ‘%n’ to insert the users name from the original from header
; and ‘%s’ to insert the localized sitename.
dmarc_compliant_from_displayname = ‘%n’

; Amount of time required between attempts to send non-editorial emails
; in seconds. This can be used to help prevent email relaying via OJS.
time_between_emails = 3600

; Maximum number of recipients that can be included in a single email
; (either as To:, Cc:, or Bcc: addresses) for a non-privileged user
max_recipients = 10

; If enabled, email addresses must be validated before login is possible.
require_validation = Off

; Maximum number of days before an unvalidated account expires and is deleted
validation_timeout = 14

i put your configuration but it does not work

There was an error sending this email. Please check your PHP error log for more information.

Stack Trace:

File: /home/web/public_html/ojs/lib/pkp/classes/mail/PKPMailTemplate.inc.php line 237
Function: Mail->send()

File: /home/web/public_html/ojs/classes/mail/MailTemplate.inc.php line 163
Function: PKPMailTemplate->send(True)

File: /home/web/public_html/ojs/lib/pkp/pages/login/PKPLoginHandler.inc.php line 211
Function: MailTemplate->send()

File: (unknown) line (unknown)
Function: PKPLoginHandler->requestResetPassword(Array(0), Object(Request))

File: /home/web/public_html/ojs/lib/pkp/classes/core/PKPRouter.inc.php line 362
Function: call_user_func(Array(2), Array(0), Object(Request))

File: /home/web/public_html/ojs/lib/pkp/classes/core/PKPPageRouter.inc.php line 220
Function: PKPRouter->_authorizeInitializeAndCallRequest(Array(2), Object(Request), Array(0), False)

File: /home/web/public_html/ojs/lib/pkp/classes/core/Dispatcher.inc.php line 134
Function: PKPPageRouter->route(Object(Request))

File: /home/web/public_html/ojs/lib/pkp/classes/core/PKPApplication.inc.php line 178
Function: Dispatcher->dispatch(Object(Request))

File: /home/web/public_html/ojs/index.php line 64
Function: PKPApplication->execute()

This solution Can't setup custom email using sendgrid instead of inbuilt phpmailer? - #9 by Pankaj_Kumar is work for me.

Can you check this:
smtp_username = apikey (you do not need to change it)
smtp_password = pass (your API key like SG.p…)

Also, you need to pass this step: “Single Sender Verification” on the SendGrid account.

It is restricted to 100 emails per day?

Any other similar service offering a better plan

should I use

smtp_username = info@domainname.com
smtp_password = Abs@123

or I use

smtp_username = apikey
smtp_password = pass

but how I get API key ???