-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to adapt php.ini for non-standard sendmail emailing? #15
Comments
I haven't used Sendgrid before, so I'm not completely aware what options they offer. If they offer SMTP login using a domain or IP and login details, that can easily be configured straight in php.ini. If it only supports some kind of JSON or XML API, then I would guess applications would specifically need to implement support for Sendgrid. Could you maybe elaborate on that a bit? I can then see what solutions are possible. |
Thanks for getting back to me so soon! I wasn't expecting it hahaha Thank you for prompting me to research this deeper! After looking at their documentation it looks as though you can sign in using SMTP login as outlined here. There's also an alternate PHP example here,. So, if I understand correctly, I can just supply php.ini with sendgrid's details as per their documentation and that should work? In that case that's much easier than I was expecting hahaha. I'll also post the php example if that is relevant here if you're interested! sendgrid's php example code<?php
require 'vendor/autoload.php'; // If you're using Composer (recommended)
// Comment out the above line if not using Composer
// require("/sendgrid-php.php");
// If not using Composer, uncomment the above line and
// download sendgrid-php.zip from the latest release here,
// replacing with the path to the sendgrid-php.php file,
// which is included in the download:
// https://github.com/sendgrid/sendgrid-php/releases
$email = new \SendGrid\Mail\Mail();
$email->setFrom("test@example.com", "Example User");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("test@example.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
} |
Seems like you can indeed chose between using SMTP credentials or implementing their API into the application. In case of Tabby, I didn't really want to figure out all the different APIs for the more popular email services (Google, Microsoft, Sendgrid, Mailgun, Mailjet, Twilio, ...), especially since I don't want to encourage the use of external and/or closed source solutions but try to adhere to the selfhosted concept of https://github.com/awesome-selfhosted/awesome-selfhosted/ . Luckily, it seems Sindgrid offers SMTP credentials you can configure in php.ini for all your PHP applications, which is much cleaner and simpler, and very similar to the setup I use (but I use a local email server). Hopefully you can get things working that way. If you get it set up perfectly, please let me know (and feel free to close the issue at that point). I might clarify further in a next release that you can configure SMTP credentials easily through php.ini, since I don't mention that in the message you quoted. |
Great! I'll try to get it set up soon and let you know if it works! Also if you don't mind, could you share what kind of email server you use? I may try my hand at running my own eventually and only just started looking into different software and docker images. |
Oh I think I have it almost finished, but I ran into the following error when actually trying to send the email out:
I realized I hadn't installed sendmail, so I ran apt-get to install it, but it's still running into the same error. Is there some value in pbp.ini that I'm missing that needs to be set? |
Okay some updates My issues with sendmail in the above comments was because I was running tabby in docker as per the instructions found here, since I prefer to run things in docker where possible. However sendmail wasn't included in this configuration, so I had to connect to the docker container and running Now I'm running into this error: I modified the docker launch command like so: And no dice. As this is im sure far beyond the intended setup, I will abandon using docker and try with a standard nginx host configuration and update once i get something working. |
OKAY FINALLY GOT IT WORKING WITH SENDGRID I followed these instructions using the sendgrid credentials. Just in case the guide ever falls or someone needs exact instructions here's how I did it using sendgrid with sendmailRequirements: Sendgrid and a sendmail account with a verified domain name.First install sendmail if you haven't already. I used Change the hostname if you'd like using /etc/hosts but it's not needed. Run the following commands: sudo mkdir /etc/mail/authinfo
sudo chmod -R 700 /etc/mail/authinfo
cd /etc/mail/authinfo
sudo nano smtp-auth now paste the following, replacing AuthInfo: "U:root" "I:apikey" "P:actual-api-key" Next run this command: sudo makemap hash smtp-auth < smtp-auth Now to edit the sendmail.mc cd /etc/mail
sudo nano sendmail.mc paste this right below the define(`SMART_HOST',`[smtp-host]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/smtp-auth.db')dnl Then run Assuming you're using nginx, edit the following file, replacing $VERSION with yoiur actual php version Restart nginx and php
And that should be it! Feel free to @ me if anyone has any questions. |
Seems you have been busy! Sorry for the late reply, I had a crazy day at work and some stuff I still had to do around the house. Hmmm, if I understand things correctly, you are now using sendmail with the sendgrid SMTP instead of using the sendgrid SMTP directly in PHP. That's also possible, but a lot more complicated I think. But I'm glad you got it working! :D To answer your earlier question: I run postfix with a MySQL backend to define mailboxes and aliases, I use dovecot as the LDA (so I can use sieve and managesieve) and for IMAP, and use amavis with spamassassin for anti-spam. It's not a complicated setup, but it can be challenging to start to understand the components. |
No problem!! and yeah, I switched to SMTP + sendmail because apparently php on linux systems doesn't support SMTP?? at least without installing and configuring something else. This way ended up being easier. I saw postfix come up repeatedly on my searches! I'll def look into it sometime, maybe even try a mail server docker out now that I know how to get sendgrid working with SMTP credentials. It sounds challenging but thanks for telling me anyways! It'll be good to have something to launch off of! |
I was trying out tabby today and saw this text on the installation screen
With a link to php documentation here.
My question is, are there any examples of ways to adapt php.ini for non standard email set ups? I currently don't have a working sendmail on my server, and usually use sendgrid for other applications that have the built in support for it. Is using sendgrid here even possible? Or is sendmail the only way to use this application?
Many thanks in advance.
The text was updated successfully, but these errors were encountered: