Skip to content

Unable to send email using SendmailMailer in v4.0.2 #96

Description

@zabous

Version: 4.0.2

Bug Description

I have very simple code to send email using SendmailMailer.
Everything is working in nette/mail v3.1.11. When I upgrade to nette/mail v4.0.2 there is error:

Nette\Mail\SendException - Unable to send email

Steps To Reproduce

Try this code with nette/mail v3.1.11 (working) and with v4.0.2 (not working)

$mail = new Nette\Mail\Message;
$mail->setFrom('Franta <franta@example.com>')
	->addTo('petr@example.com')
	->setSubject('Potvrzení objednávky')
	->setBody("Dobrý den,\nvaše objednávka byla přijata.");
$mailer = new Nette\Mail\SendmailMailer;
$mailer->send($mail);

It seems to me, that the problem is on line SendmailMailer.php on line 52 - after removal it work ok.
$cmd .= ' -f' . key($from);

Expected Behavior

Code is working with both versions (v3.1.11 and v4.x.x)

Activity

  1. dg commented on Dec 20, 2023

    @dg
    Member

    Related to #78

  2. milo commented on Jan 30, 2024

    @milo
    Member

    Setting an envelope address (-f $from) is correct from more points of view.

    • receiving MTA puts this address into message as a Return-Path header and uses it for bounce messages (mailbox full, mailbox does not exist, ...)
    • receiving MTA uses envelope address for SPF policy evaluation (not sure it's standard, at least GMail does it) which is todays quite important

    @zabous Your problem can be on more levels. Default PHP sendmail command is sendmail_path = sendmail -t -i. Maybe your hosting modified it, should be seen in php info.

    The sendmail command is quite UNIX standard and many non-sendmail MTA emulates it. Maybe it is not full compatible.

    Or sending MTA does not allow $from to be envelope address. Such error could be found in mail log, not sure you can access it.

  3. zabous commented on Jan 30, 2024

    @zabous
    ContributorAuthor

    I see my phpinfo() that "sendmail_path" on my hosting is set to "/usr/bin/msmtp -C /etc/msmtprc -t --read-envelope-from"
    It works fine without ' -f' param.
    @milo is there some problem in this setting?

    I cannot access mail log - should I try to ask my provider for my mail logs?

  4. milo commented on Jan 31, 2024

    @milo
    Member

    From msmtp man page, parameter --read-envelope-from ensures same behaviour. I cannot test it but probably additional -f is evaluated as an error.

    This is hard to solve in some automatic way. Anyway, I think passing -f is correct in most cases. Possible solutions in my mind:

    • add SendmailMailer::setEnvelopeFrom(bool) or introduce __construct() params
    • somehow detect it from sendmail_path INI setting, but there are many sendmail clones

    Or you can try to use SmtpMailer, there will be probably available localhost:25 SMTP connection.

  5. zabous commented on Jan 31, 2024

    @zabous
    ContributorAuthor

    Parameter -f is correct in most cases? I'm afraid that's not enough for general library.
    In my opinion, it is better to leave the -f parameter to the developer using the library.

    Thanks for the advice with SendmailMailer::setEnvelopeFrom(bool). That can be helpful, but I cannot find this function in SendmailMailer.

    Is there another way to turn off adding the -f parameter?

  6. milo commented on Jan 31, 2024

    @milo
    Member

    Parameter -f is correct in most cases? I'm afraid that's not enough for general library. In my opinion, it is better to leave the -f parameter to the developer using the library.

    Yes. It is correct to set envelope address to From header.

    Thanks for the advice with SendmailMailer::setEnvelopeFrom(bool). That can be helpful, but I cannot find this function in SendmailMailer.

    It is only an idea how to solve it by pull request.

    Is there another way to turn off adding the -f parameter?

    No. Send pull request with explanation.

  7. dg commented on Oct 4, 2024

    @dg
    Member

    added SendmailMailer::setEnvelopeSender()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions