Code Monkey home page Code Monkey logo

mail's Introduction

Nette Mail: Sending E-mails

Downloads this Month Tests Coverage Status Latest Stable Version License

Introduction

Are you going to send emails such as newsletters or order confirmations? Nette Framework provides the necessary tools with a very nice API.

Documentation can be found on the website.

Do you like Nette Mail? Are you looking forward to the new features?

Buy me a coffee

Thank you!

Installation

composer require nette/mail

It requires PHP version 8.0 and supports PHP up to 8.3.

Creating Emails

Email is a Nette\Mail\Message object:

$mail = new Nette\Mail\Message;
$mail->setFrom('John <[email protected]>')
	->addTo('[email protected]')
	->addTo('[email protected]')
	->setSubject('Order Confirmation')
	->setBody("Hello, Your order has been accepted.");

All parameters must be encoded in UTF-8.

In addition to specifying recipients with the addTo() method, you can also specify the recipient of copy with addCc(), or the recipient of blind copy with addBcc(). All these methods, including setFrom(), accepts addressee in three ways:

$mail->setFrom('[email protected]');
$mail->setFrom('[email protected]', 'John Doe');
$mail->setFrom('John Doe <[email protected]>');

The body of an email written in HTML is passed using the setHtmlBody() method:

$mail->setHtmlBody('<p>Hello,</p><p>Your order has been accepted.</p>');

You don't have to create a text alternative, Nette will generate it automatically for you. And if the email does not have a subject set, it will be taken from the <title> element.

Images can also be extremely easily inserted into the HTML body of an email. Just pass the path where the images are physically located as the second parameter, and Nette will automatically include them in the email:

// automatically adds /path/to/images/background.gif to the email
$mail->setHtmlBody(
	'<b>Hello</b> <img src="background.gif">',
	'/path/to/images',
);

The image embedding algorithm supports the following patterns: <img src=...>, <body background=...>, url(...) inside the HTML attribute style and special syntax [[...]].

Can sending emails be even easier?

Emails are like postcards. Never send passwords or other credentials via email.

Attachments

You can, of course, attach attachments to email. Use the addAttachment(string $file, string $content = null, string $contentType = null).

// inserts the file /path/to/example.zip into the email under the name example.zip
$mail->addAttachment('/path/to/example.zip');

// inserts the file /path/to/example.zip into the email under the name info.zip
$mail->addAttachment('info.zip', file_get_contents('/path/to/example.zip'));

// attaches new example.txt file contents "Hello John!"
$mail->addAttachment('example.txt', 'Hello John!');

Templates

If you send HTML emails, it's a great idea to write them in the Latte template system. How to do it?

$latte = new Latte\Engine;
$params = [
	'orderId' => 123,
];

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

File email.latte:

<html>
<head>
	<meta charset="utf-8">
	<title>Order Confirmation</title>
	<style>
	body {
		background: url("background.png")
	}
	</style>
</head>
<body>
	<p>Hello,</p>

	<p>Your order number {$orderId} has been accepted.</p>
</body>
</html>

Nette automatically inserts all images, sets the subject according to the <title> element, and generates text alternative for HTML body.

Sending Emails

Mailer is class responsible for sending emails. It implements the Nette\Mail\Mailer interface and several ready-made mailers are available which we will introduce.

SendmailMailer

The default mailer is SendmailMailer which uses PHP function mail(). Example of use:

$mailer = new Nette\Mail\SendmailMailer;
$mailer->send($mail);

If you want to set returnPath and the server still overwrites it, use $mailer->commandArgs = '[email protected]'.

SmtpMailer

To send mail via the SMTP server, use SmtpMailer.

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

The following additional parameters can be passed to the constructor:

  • port - if not set, the default 25 or 465 for ssl will be used
  • timeout - timeout for SMTP connection
  • persistent - use persistent connection
  • clientHost - client designation
  • streamOptions - allows you to set SSL context options for connection

FallbackMailer

It does not send email but sends them through a set of mailers. If one mailer fails, it repeats the attempt at the next one. If the last one fails, it starts again from the first one.

$mailer = new Nette\Mail\FallbackMailer([
	$smtpMailer,
	$backupSmtpMailer,
	$sendmailMailer,
]);
$mailer->send($mail);

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

DKIM

DKIM (DomainKeys Identified Mail) is a trustworthy email technology that also helps detect spoofed messages. The sent message is signed with the private key of the sender's domain and this signature is stored in the email header. 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.

$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($signer);
$mailer->send($mail);

mail's People

Contributors

andrewsville avatar bretislavstepan avatar dg avatar dundee avatar enumag avatar fprochazka avatar grongor avatar jakubboucek avatar janbarasek avatar janbuchar avatar janedbal avatar jantvrdik avatar jkrcma avatar juzna avatar kravco avatar krulis-martin avatar lukaspijak avatar mstrouhal avatar mzk avatar ondrejcech avatar pavolbiely avatar pepakriz avatar petrkle avatar podolinek avatar pracj3am avatar robbertkl avatar storkdork avatar vrana avatar xificurk avatar zzromanzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mail's Issues

fwrite(): SSL: Broken pipe

Hello Developer,Thank you for developing tools that surprised me so much,It really makes me feel particularly easy and convenient.

but i have a problem ,when i send attachment with mail,

It occasionally tells me this happened fwrite(): SSL: Broken pipe
I checked this question and I found that this error is bound to occur whenever I send a larger attachment

Can you help me to fix this problem? thank you very much


[think\exception\ErrorException]
fwrite(): SSL: Broken pipe

Exception trace:
() at /data/www/screenWeb/vendor/nette/mail/src/Mail/SmtpMailer.php:195
think\Error::appError() at n/a:n/a
fwrite() at /data/www/screenWeb/vendor/nette/mail/src/Mail/SmtpMailer.php:195
Nette\Mail\SmtpMailer->write() at /data/www/screenWeb/vendor/nette/mail/src/Mail/SmtpMailer.php:111
Nette\Mail\SmtpMailer->send() at /data/www/screenWeb/application/common/logic/MailLogic.php:50
app\common\logic\MailLogic->sendMail() at /data/www/screenWeb/application/spider/controller/Push.php:100

Spam report: BASE64_LENGTH_79_INF

First of all thank you very much for your work.

I comment that when sending emails with an attached pdf document mailtrap.io indicates this in your spam report:

Pts Rule name Description
2.0 BASE64_LENGTH_79_INF BODY: base64 encoded email part uses line

To generate the PDF file I am using mpdf.

I did not find information about it and for this reason I go to you.

Thank you very much!

Backtrack limit was exhausted with base64 encoded image

Version: 3.1.5

Bug Description

Whenever there is a bigger base64 encoded image in E-mail we get this exception:
image

Steps To Reproduce

It's clear from bug description

Additional

I'm not sure how to even solve this, avoiding Regex if possible would maybe be best since we never know how big e-mail can be and with base64 encoded images this can become huge quickly...
I know I can set bigger limit, but then again how much memory will it use and when will we hit it again...
Probably only proper solution here would be to add image as attachment and not base64 encoded...
I've managed to avoid issue in this particular mail since we're not using any images so I just set basePath as null so it doesn't go into this part of code, but obviously that's not a solution...

HTML Decode errors?

When i got an error: Fatal error: Uncaught Nette\Mail\SendException: Unable to send email: Failed to connect to mailserver at &\quot;ssl://smtp.gmail.com&\quot; port 465, verify your &\quot;SMTP&\quot; and &\quot;smtp_port&\quot; I think it's not beautiful.. Than i change this: (48-51 line @ SendmailMailer.php)

$info = ": $message";
});
if ($res === FALSE) {
    throw new SendException("Unable to send email$info.");

to this

$info = $message;
});
if ($res === FALSE) {
    throw new SendException("Unable to send email: " . html_entity_decode($info));

and the result little bit beautiy for client eyes:
Fatal error: Uncaught Nette\Mail\SendException: Unable to send email: Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

I put backslashes, so you see the problem, because on preview that's decode, but in script no))
Thank you.

Exception is raised when html body contains url with 'src' link

Creating email message with html body, which contains query string with "src" name in some url, throws FileNotFoundException.

$message = new Nette\Mail\Message();
$message->setHtmlBody("<a href='test.php?src=SOME'>some link</a>");

throws FileNotFoundException with message "Unable to read file /SOME"

Because it completely crashes sending particular email, it's serious bug.

Maybe there are another use cases with src string in html, which can also hit this bug.

Support for TLS 1.2 SMTP

Version: 2.4

Bug Description

If SMTP server support only TLS 1.2 isn't possible connect it.

Expected Behavior

In SmtpMailer is now this:
stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)

i found solution on php.net

$cryptoMethod = STREAM_CRYPTO_METHOD_TLS_CLIENT;

if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
$cryptoMethod |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
$cryptoMethod |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
}

if (!stream_socket_enable_crypto($this->connection, true, $cryptoMethod)) {
throw new SmtpException('Unable to connect via TLS.');
}

What do you think?

SMTP login with blank password

Hi, its possible update SmtpMailerClass to work with blank smtp password? Now its skip login on

if ($this->username != null && $this->password != null) {

but change to

if ($this->username != null && $this->password !== null) {

solve this.

Some email debug tools accept only logins with username without password...

Underscore prefix on long attachment names

When I am using long names for mail attachments, the attachment name starts with an underscore, even though I did not set an underscore:

Content-Type: text/plain; name="_XXXXXXX_YYYYYYY_ZZZZZZZ_123456789.csv" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment;filename="_XXXXXXX_YYYYYYY_ZZZZZZZ_123456789.csv"

Do you know what might cause this problem?

Throw fatal error

  • bug report? yes
  • feature request? no
  • version: 2.4.2

No work. i am attempting to send a mail but it give me this:
Fatal error: Uncaught Error: Class 'Nette\Mail\Message' not found in C:\xampp\htdocs\Pasantias pdf\Registro\componentes\correo.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Pasantias pdf\Registro\componentes\correo.php on line 4

my code is the following:
use Nette\Mail\Message;

$mail = new Message;
$mail->setFrom('Jorge ********@gmail.com')
->addTo('@gmail.com')
->setSubject('Order Confirmation')
->setBody("Hello, Your order has been accepted.");
$mailer = new Nette\Mail\SmtpMailer([
'host' => 'smtp.gmail.com',
'username' => '
@gmail.com',
'password' => '
*****',
'secure' => 'ssl',
'context' => [
'ssl' => [
'capath' => '/path/to/my/trusted/ca/folder',
],
],
]);
$mailer->send($mail);

eml attachments

  • bug report? yes
  • feature request? yes
  • version: 2.4

Wrong content type for .eml files added as attachment

Hi, if you add eml file (mail file) to mail message attachments and send, some mail servers (in my case seznam.cz) reply me:

You message for <...@...> from 2017/11/29 could not be delivered.
It's attached below.

Důvod / Reason:
---------------

5.6.5 ebox; ebox: bad argument: Rfc822 message part can not be conbinated with base64 encoding.

It noticed me about wrong content type of attachment, which is "correctly" set as Rfc822, but this content type is not allowed for attached files.

Chapter 4.4 of whitepapers from microsoft describes how to fix it: change content-type to APPLICATION/OCTET-STREAM.

This should be fine implemented at nette mail for example at Message.php.

public function addAttachment($file, $content = null, $contentType = null) {
	$path = $file;
	$ext = Strings::lower(pathinfo($path, PATHINFO_EXTENSION));
	if ($ext == 'eml') {
		$contentType = $contentType ?? 'APPLICATION/OCTET-STREAM';
	}
	return $this->attachments[] = $this->createAttachment($file, $content, $contentType, 'attachment');
}

What do you think about this change?

Regards,
Ondrej

mail twice

  • bug report? yes/no
  • feature request? yes/no
  • version: ?.?.?

Description

after required this composer, every time i send email to me, i will receive email twice! why?

Steps To Reproduce

... If possible a minimal demo of the problem ...

SmtpMailer leaves a connection mid-communication when not able to build a message

  • bug report? yes
  • feature request? no
  • version: trunk

Description

Before the Message::generateMessage() method gets called, there is already some communication with the SMTP server. If the method for some reason throws an exception other than Nette\Mail\SmtpException, sending the message aborts but the connection is kept open. If you send another message using the same sender, the SMTP server will probably return something like 503 sender already given because from its point of view you are still sending the first faulty message.

How can this happen: Using vanilla Nette\Mail\Message it probably can't. However because of how the Message builds itself when being sent and because the $parts property is private, it is impossible to build a wrapper/proxy/decorator/something that would encapsulate an existing message and encrypt/sign it for example. The only feasible way I've found is a to subclass the Message class and handle the signature/encryption part inside the build() method. And this can obviously fail. And if it throws something else than Nette\Mail\SmtpException GO TO previous paragraph.

The fix is simple - only change the order of things inside SmtpSender::send(). PR #43 present.

Steps To Reproduce

Throw an exception (any other than Nette\Mail\SmtpException) from Message::build() or Message::generateMessage() and try sending another message (with or without such exception) on the same sender.

setSubject went wrong sometime

when i use setSubject('sss') or setSubject('sssssssssssssssssssssss') or setSubject(s*N) , it output "SMTP server did not accept . with error: 554……" , HOW ODD!!!

date not safe error - nette/mail/src/Mail/Message.php on line 51

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/vhosts/example.com/httpdocs/vendor/nette/mail/src/Mail/Message.php on line 51

My timezone is

php -i | grep timezone
Default timezone => Europe/Istanbul
date.timezone => Europe/Istanbul => Europe/Istanbul

What do I have to do?

SendMailMailer: confusing error message

When mail function fails, it does not always create error. For instance you can get error which was earlier created by this code http://api.nette.org/2.1.0/source-Caching.Storages.FileStorage.php.html#325.

Unable to send email: fopen(/home/honza/vec/temp/cache/_Nette.FileTemplate/_Email.RegisterEmail.latte-d7ce40e6e36469422781c16e335ac069.php)

I suggest to improve the exception message. This might be better:

Function mail() failed. Last error: $error[message]

IMAP wrapper rewrite request

How to re-write this code with nette imap wrapper ?

	//sent email to send folder
		$imap = imap_open("{mail.argoscms.pw:993/imap/ssl/novalidate-cert}INBOX.Sent", "email", "password");
		$check = imap_check($imap);
		imap_append($imap, "{mail.argoscms.pw:993/imap/ssl/novalidate-cert}INBOX.Sent"
						   , "From: ".$admin_email."\r\n"
						   . "To: ".$his_mail."\r\n"
						   . "Subject: Message from ".$site_name."\r\n"
						   . "\r\n"
						   . "".$our_text."\r\n"
		);

		$check = imap_check($imap);
		imap_close($imap);

[Documentation]

Please rewrite the documentation for SmtpMailer class. You can see the difference between documentation and the code from pictures below

IMG_20231129_171702.jpg

IMG_20231129_171603.jpg

Support self-signed certificates

Hello

we have some SMTP servers with self signed SSL certificates. They do not work and currently are failing due to stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

Would it be possible to add some configuration option verify = false to be able to make this configuration work?

Seems like laravel/symfony mailers support it (according to https://stackoverflow.com/a/61588084). It would be very nice if Nette would support it as well please.

Thank you
Jakub

Envelope address passed to sendmail

We just encountered increasing undelivered messages rate on certain recipient server and it was caused by mismatch between From header and envelope address. Then we found out that Nette did not pass required parameter (-f) to sendmail automatically and it must be set manually. I would expect this would be handled by mailer.

We solved it by replacing default SendmailMailer by this child class:

class SendmailMailer extends \Nette\Mail\SendmailMailer {

  public function send(Message $mail)
  {
    $from = array_keys($mail->getFrom());
    if($from) {
      $this->commandArgs = "-f".reset($from);
    }
    parent::send($mail);
    $this->commandArgs = null;
  }

}

I just think this should either be default behaviour (is the any case when yo do not want to pass -f parameter?) or be configurable either by providing subclass (EnvelopeSendmailMailer, FromSendmailMailer, ...) as we did it or even better maybe as option (setPassEnvelopeFrom()) of SendmailMailer.

Custom File Name

Could you add the ability to specify a custom file name for addAttachment ?

UTF8 in attachment filename is not encoded

Version: 3.1.4

Bug Description

If the attachment file name contains UTF8 characters, the header is not RFC 2047 encoded, which causes email to rely on support of SMTPUTF8 extension, making the email undeliverable to destinations servers that don't support it (gmail supports it, but e.g. email.cz does not).

Steps To Reproduce

$mail = new Nette\Mail\Message;
$mail->setFrom('John <[email protected]>')
        ->addTo('[email protected]')
        ->setSubject('Kůň v příloze')
        ->setBody("Test")
        ->addAttachment("kůň.txt", "test");

die($mail->generateMessage());

See resulting Content-Disposition header:

Content-Disposition: attachment; filename="kůň.txt"

Expected Behavior

Content-Disposition: attachment; filename="=?UTF-8?B?a8WvxYgudHh0?="

Possible Solution

This worked in the previous version, the bug was introduced with this change 6f33373 which fixed #24, in this change, call to encodeHeader() has been removed. This call should be probably returned, but I'm not sure how exactly in order to not introduce back the issue #24.

I know a workaround is not to use utf8 in attachment file name with e.g. Strings::toAscii($filename), but as long as the encoding works well with other headers like Subject or From, I don't see a reason for this header to be an exception.

From doesn't expect localhost

My application sends emails. I didn't want to hardcore the domain into it, so that I got it from HttpResponse. Unfortunately if I debug the app on a development machine and I access it through localhost as a domain, it throws

Nette\Utils\AssertionException
    The header 'From' expects to be email, string 'email@localhost' given.

I have to put there something like localhost.cz.

Embed file are not catched

Version: 3.1

Bug Description

Embed files (images) <img src=".....> are not matched/replaced correctly in Message::setHtmlBody().

Steps To Reproduce

$html = '<img src="C:\Users\FRANTA\projects\Project-X\temp\content\con33C8.svg">';
Message::setHtmlBody($html, '');

will produce:

<img src="C:\Users\FRANTA\projects\Project-X\temp\content\con33C8.svg">

instead of

<img src="cid:xyyrj49su6@localhost">

Expected Behavior

<img src="C:\Users\FRANTA\projects\Project-X\temp\content\con33C8.svg"> converted to <img src="cid:xyyrj49su6@localhost">

Possible Solution

Modify regex in Message::setHtmlBody()
Patter <img[^<>]*\s src\s*=\s* will not catch path contains colons : or spaces .

For images in different folders i can not use param $basePath
Example of used images in html body:
C:\Users\FRANTA\projects\Project-X\temp\content\con33C8.svg
C:\Users\FRANTA\projects\Project-X\app\some folders with spaces\xxxx.jpg
./another folder in root/sub folder/yyyy.png

Propagates links target from HTML message to plaintext version

This functionality doesn't work correct. This HTML body:

<a href="https://www.nette.org">Nette.org</a><br>
<a href="https://www.google.com/">Google.com</a>

generates this plaintext version:

Google.com <https://www.nette.org">Nette.org

The test is passing because there are used single quotes in second link, if you change it to double quotes the result will be wrong.

Unable to send email using SendmailMailer in v4.0.2

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 <[email protected]>')
	->addTo('[email protected]')
	->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)

SendmailMailer: Impossible to set commandArgs

Version: 4.0.0

Bug Description

Commit 0e236e4 breaks sending mails with set "From" when SendmailMailer::$commandArgs is also set.
In that case function mail() is invoked with 6 parameters instead of expected 5 parameters.

Steps To Reproduce

$mail = new \Nette\Mail\Message();
$mail->setFrom('[email protected]');

$mailer = new \Nette\Mail\SendmailMailer();
$mailer->commandArgs = '[email protected]';
$mailer->send($mail);

Produces ArgumentCountError "mail() expects at most 5 arguments, 6 given".

Expected Behavior

Function mail() is successfully invoked.

Possible Solution

Command arguments from mailer must be concatenated with value from message.

Type error in Message->getPriority()

getPriority has return type ?int but getHeader returns mixed|null (in my case numeric string '3').

return $this->getHeader('X-Priority');

Can I send a PR with a fix?

$priority = $this->getHeader('X-Priority');
return is_numeric($priority) ? (int) $priority : null;

SMTP server did not accept STARTTLS with error: 503 5.5.2 Send hello first

Version: 3.1.3

Bug Description

After upgrading nette/mail to version 3.1.3 from 3.1.2, the e-mails won't send with exception:

Nette\Mail\SmtpException
SMTP server did not accept STARTTLS with error: 503 5.5.2 Send hello first [DB5EUR03FT018.eop-EUR03.prod.protection.outlook.com]

I suspect this pull request #67 to be an issue.

Steps To Reproduce

Send e-mail with this settings:

[
  'host' => '<hidden>.mail.protection.outlook.com',
  'port' => 25,
  'secure' => 'tls',
]

Expected Behavior

E-mail is sent

Possible Solution

Revert the pull request #67

How to properly include HTML email in setHTMLBody function?

First let me tell you my needs with Nette mail.

I have a simple checkout done via Stripe. After successful charge is made, using Stripe webhooks for that event I need to send email with attachment.

For sending emails I looked at Mailgun and Sendgrid, but it seems they have issues with sending email to Outlook, I guess Outlook blocks their emails if not sent via dedicated IP.

Then I started looking for a simple PHP solution(since the charge is done via PHP) and found Nette mail. But I am having trouble adding HTML part to Nette mail.

In the examples you use your templating language, can it be done without it? Do I need to stringify my HTML code first?

p.s. I don't work with PHP, sorry if this is a stupid question :)

Message serializator

Hello,

I think there should be an official way for Message to serialize it to a string, for example. There should also be a method that converts the serialized string back to a Message instance with the same content.

This feature can be useful when storing messages in a database and sending them through a queue.

The serialized Message should be without attachments (only a reference to the disk path, or omit completely) and be stored as a simple string including headers.

For example:

To: Jan <[email protected]>
From: Nette <[email protected]>
Subject: My awesome message!

<!-- HTML body -->
<p>Hello, how are you?</p>

Text content does not have to be included, because we can always calculate it from HTML.

Thank you.

To: undisclosed-recipients

I would like to suggest a modification of SmptMailer to define "To:" header with undisclosed-recipients: ; content when Bcc was removed and no other recipient headers are sent. I have been just struggling with sendmail SMTP server that does not like it when no "To" header is set (and I need to send only anonymous notifications from my Nette app).

I think adding

		if (!$tmp->getHeader('To') && !$tmp->getHeader('Cc')) {
			// missing recipient headers make some mailers (e.g., sendmail) nervous, so we set To like MTAs does
			$tmp->setHeader('To', 'undisclosed-recipients: ;');
		}

right after line 75 (where $tmp->setHeader('Bcc', null); is) in SmptMailer.php should do the trick...

Undefined index SMTP

Version: 3.0-dev
From commit: 6e88a3e

Bug Description

Undefined index: smtp - on line 45 in src/Bridges/MailDI/MailExtension.php
if ($this->config['smtp']) {

Steps To Reproduce

If throws error only sometime, on one page immediately or after some refreshes.

EDIT: It seems that there is more similar notices, Tracy report i.e. indexes 'debugger', 'users', 'roles', etc. in SecurityExtension, 'netteMailer', 'bar', 'blueScreen' in TracyExtension.
And problems are with foreaches that use $this->config['xxx']. Seems that there is problem with missing Nette\DI\Config\Expect, that was deleted.

Possible Solution

Check if exists index, or other solution used for config array.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.