Skip to content
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

Add support for per app credentials when sending mails #6

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add support for per app credentials when sending mails
  • Loading branch information
maminrayej committed Oct 15, 2024
commit 177af9441e95e967cbf6c9da15fd42a61f2172ec
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ build/PHP-Parser-*
config.h
config.h.in
/ext/date/lib/timelib_config.h
/ext/standard/mail_wasix_credentials.h
/main/build-defs.h
/main/php_config.h.in
/main/php_config.h
Expand Down
10 changes: 0 additions & 10 deletions ext/standard/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,8 @@ dnl
dnl Include libwasix_sendmail when building to WASIX
dnl
if test "$ac_cv_have_decl___wasi__" == "yes"; then
rm ext/standard/mail_wasix_credentials.h || true

if test -n "$WASIX_SENDMAIL_LIBS"; then
PHP_EVAL_LIBLINE($WASIX_SENDMAIL_LIBS)

if test -n "$SENDMAIL_DEFAULT_USERNAME"; then
echo "#define SENDMAIL_DEFAULT_USERNAME \"$SENDMAIL_DEFAULT_USERNAME\"" >> ext/standard/mail_wasix_credentials.h
fi

if test -n "$SENDMAIL_DEFAULT_PASSWORD"; then
echo "#define SENDMAIL_DEFAULT_PASSWORD \"$SENDMAIL_DEFAULT_PASSWORD\"" >> ext/standard/mail_wasix_credentials.h
fi
fi
fi

Expand Down
15 changes: 12 additions & 3 deletions ext/standard/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
} \

#ifdef __wasi__
# include "mail_wasix_credentials.h"
# define WASMER_EDGE_MAIL_POSTFIX "@wasmeredgemail.com"
#endif

Expand Down Expand Up @@ -382,6 +381,11 @@ int wasix_sendmail(const char *host, uint16_t port, const char* username, const
const char *headers, const char *subject, const char *mail_from, const char *mail_to, const char *data);
#endif

#ifdef __wasi__
const char *username_env_var = "APP_MAIL_USERNAME";
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
const char *password_env_var = "APP_MAIL_PASSWORD";
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
#endif

/* {{{ php_mail */
PHPAPI int php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd)
{
Expand Down Expand Up @@ -489,8 +493,8 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co

smtp = "smtp.mailgun.org";
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
smtp_port = 587;
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
username = SENDMAIL_DEFAULT_USERNAME;
password = SENDMAIL_DEFAULT_PASSWORD;
username = getenv(username_env_var);
password = getenv(password_env_var);

if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY ||
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
Expand Down Expand Up @@ -528,6 +532,11 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
}
}

if (!username || !password) {
fprintf(stderr, "Username or password for mail is not provided\n");
MAIL_RET(1);
}

wasix_sendmail_result = wasix_sendmail(
smtp,
smtp_port,
Expand Down
2 changes: 1 addition & 1 deletion wasix-test-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TEST_SERVER=${TEST_SERVER:-localhost:8080}
ALL_TESTS=( \
sqlite \
sqlite-pdo \
mail \
# mail \
maminrayej marked this conversation as resolved.
Show resolved Hide resolved
mysql \
mysql-pdo \
pgsql \
Expand Down
Loading