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

Update SendmailMailer.php - setting envelope addres can be disabled #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 21 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Images can also be extremely easily inserted into the HTML body of an email. Jus
// automatically adds /path/to/images/background.gif to the email
$mail->setHtmlBody(
'<b>Hello</b> <img src="background.gif">',
'/path/to/images'
'/path/to/images',
);
```

Expand Down Expand Up @@ -118,14 +118,14 @@ $mail = new Nette\Mail\Message;
$mail->setFrom('John <[email protected]>')
->addTo('[email protected]')
->setHtmlBody(
$latte->renderToString('email.latte', $params),
'/path/to/images'
$latte->renderToString('/path/to/email.latte', $params),
'/path/to/images',
);
```

File `email.latte`:

```html
```latte
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -174,22 +174,22 @@ SmtpMailer
To send mail via the SMTP server, use `SmtpMailer`.

```php
$mailer = new Nette\Mail\SmtpMailer([
'host' => 'smtp.gmail.com',
'username' => '[email protected]',
'password' => '*****',
'secure' => 'ssl',
]);
$mailer = new Nette\Mail\SmtpMailer(
host: 'smtp.gmail.com',
username: '[email protected]',
password: '*****',
encryption: Nette\Mail\SmtpMailer::EncryptionSSL,
);
$mailer->send($mail);
```

If you do not specify `host`, the value from php.ini will be used. The following additional keys can be used in the options:
The following additional parameters can be passed to the constructor:

* `port` - if not set, the default 25 or 465 for `ssl` will be used
* `context` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection
* `timeout` - timeout for SMTP connection
* `persistent` - use persistent connection
* `clientHost` - client designation
* `streamOptions` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection


FallbackMailer
Expand All @@ -201,12 +201,12 @@ It does not send email but sends them through a set of mailers. If one mailer fa
$mailer = new Nette\Mail\FallbackMailer([
$smtpMailer,
$backupSmtpMailer,
$sendmailMailer
$sendmailMailer,
]);
$mailer->send($mail);
```

Other parameters in the constructor include the number of repeat and waiting time in miliseconds.
Other parameters in the constructor include the number of repeat and waiting time in milliseconds.


DKIM
Expand All @@ -216,14 +216,14 @@ DKIM (DomainKeys Identified Mail) is a trustworthy email technology that also he
The recipient's server compares this signature with the public key stored in the domain's DNS records. By matching the signature, it is shown that the email actually originated from the sender's domain and that the message was not modified during the transmission of the message.

```php
$options = [
'domain' => 'nette.org',
'selector' => 'dkim',
'privateKey' => file_get_contents('../dkim/dkim.key'),
'passPhrase' => '****',
];
$signer = new Nette\Mail\DkimSigner(
domain: 'nette.org',
selector: 'dkim',
privateKey: file_get_contents('../dkim/dkim.key'),
passPhrase: '****',
);

$mailer = new Nette\Mail\SendmailMailer; // or SmtpMailer
$mailer->setSigner(new Nette\Mail\DkimSigner($options));
$mailer->setSigner($signer);
$mailer->send($mail);
```
2 changes: 1 addition & 1 deletion src/Bridges/MailDI/MailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getConfigSchema(): Nette\Schema\Schema
}


public function loadConfiguration()
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();

Expand Down
13 changes: 12 additions & 1 deletion src/Mail/SendmailMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class SendmailMailer implements Mailer
{
public string $commandArgs = '';
private ?Signer $signer = null;
// Setting an envelope address using command arg (-f $from) is allowed by default
private bool envelopeFrom = true;


public function setSigner(Signer $signer): static
Expand All @@ -27,6 +29,15 @@ public function setSigner(Signer $signer): static
return $this;
}

/**
* Enable/disable setting an envelope address using command arg (-f $from)
*/
public function setEnvelopeFrom(bool $envelopeFrom): static
{
$this->evelopeFrom = $envelopeFrom;
return $this;
}


/**
* Sends email.
Expand All @@ -48,7 +59,7 @@ public function send(Message $mail): void
$parts = explode(Message::EOL . Message::EOL, $data, 2);

$cmd = $this->commandArgs;
if ($from = $mail->getFrom()) {
if (($this->evelopeFrom) && ($from = $mail->getFrom())) {
$cmd .= ' -f' . key($from);
}

Expand Down