How to make sure that the email was sent in yii2? - email

In my project when the user stored a new record to database, sent to him email with to perform afterSave() Method.
How to make sure that the email was sent?

I don't think this is something to do with yii2 or the afterSave() event (as long as the afterSave event is triggered, which you can verify by Runtime Logging for example). When using PHPMailer class you can see this discussion about making sure an email has been sent.
$mail->send() will not always return true. It returns true if the part of the sending process it was involved with works. So if you send to an unknown address, but do so via gmail, gmail's servers don't know whether the address exists or not at the time, so it will be accepted and bounced later. If you were sending to a gmail address when sending through gmail, then it would fail immediately.
If an account does not exist at all, most servers (including gmail) will still give a 5.1.1 "Unknown user" response, and that will be reported correctly by PHPMailer if you send by SMTP directly to the recipient's supposed mail server (but not if you send via an intermediate server (like gmail) or using mail()). PHPMailer doesn't have built-in support for doing that, but doing it yourself only involves a call to getmxrr and setting Host manually. Also you won't need to use authentication if you send that way.
You can do various things like check if a domain exists at all - if it doesn't, mail delivery won't work. Some servers will accept all addresses and send bounces later (e.g. if they have a spam filter with a long processing queue), but if you get rejected up-front, it's a pretty sure indication that the address doesn't exist.
You need to look into bounce handling too which will allow you to remove addresses that looked ok but later proved not to be, which is an entirely separate thing from anything that PHPMailer does. I will warn you now - bounce handling is extremely unpleasant!
You should also send using tls on port 587, not ssl on 465; see the gmail example provided with PHPMailer.
I would also recommend you to send mails via an SMTP auth connection trough PHPMailer.

Related

How to track failover email notification?

I am sending email from application. My problem is when your type email address means format is correct but it may be not available anywhere.so when I am trying send such email address using SMTP through application, so how to track fail-over notification if intended recipient not found.
please suggest any approach.
There is no standard way of doing this. You might be able to make it work in some cases by parsing incoming email looking for delivery failure notices but it'll be a lot of work to keep that parsing code up to date. So at best you'll only get some of the notices. If you get a notice at all. The recipient's SMTP server may not send you anything, or the notice might get lost on it's way back to you.
The only way you are reliably get this sort of information is to host the SMTP server yourself, and deliver directly to the recipients SMTP server. In that case the SMTP server knows the status of the email's delivery and could report that to your email client via some non-standard back channel.
Note: Hosting your own SMTP server is non-trivial. And you will probably need to be on a fixed IP otherwise external SMTP servers will treat your email as spam. In case you're thinking of running one over a home connection or something.

Analog of HTTP Redirect for SMTP

In HTTP, you can tell the client who asks for example.com/foo/ that it should ask for something.else/instead.
Is there a way to do it in SMTP? That is, if the client sends a message to john#example.com, tell it to send it to jane#somewhere.else instead.
I know that I can receive the message and relay it to jane#somewhere.else. For many reasons I don't want to relay messages via my server. Instead, I want to tell the client that it should send it to another address.
The reasons include:
I cannot notify the client of a failure (well, perhaps this can be done).
My server will be blacklisted if the message was spam.
The destination server will consult blacklists with my IP and not with the original sender's IP, etc.
My motivation is:
If this were possible, perhaps it would be a better antispam measure than greylisting.
My institutional server has no antispam filters, while my personal server uses IP-based blacklists such as Spamcop. After the institutional server has received a message, I can scan the message at the client but it's too late to consult Spamcomp and to inform the sender that the message was filtered out (I consider it a must in any filtering). I wish the institutional server could simply redirect people to my personal server, which is a lot better protected and correctly informs the sender of the problem at the SMTP stage.
Sendmail provides FEATURE(redirect) to handle such cases.
It rejects recipient in reply to RCPT TO: with
551 5.1.1 User has moved; please try <newemail#example.com>
Your email server refuses to accept the recipient with hint, it is up to sending host to generate bounce message to the sender. Spammers may/will get the new email too. I do not know any email servers handling automatically such redirects.
I have not investigated how well it is handled by various email clients and level of details provided in bounce message by various email servers.

sometimes my mail server doesn't send the emails

I'm usign amazon cloud services to host my webpage. Our web site, actually sends a lot of emails per hour. In one instant our server could be asked to send 30 mails or more.
Sometimes our clients complaint about not getting emails from the web, which is connected to our mail server to send emails. This doesn't happen if we send the email directly from our addresses to theirs, so I'm pretty much know is the web page who's causing the problem.
The thing is I don't know what is happening and neither know what to look for. I've checked memory and cpu of that server and everything seems to work fine
make sure your website sends the messages with a correct bounce address (aka envelope sender address). this does not have to be the same thing as the address in the From: header. by default, this is often something like "apache#www.example.com" - I don't know about amazon). these types of bounce addresses are bad because usually you don't receive the error message if something goes wrong. use a real email account. To check what bounce address you currently use, look at the message source of a received mail and see the Return-Path header.
check the logs of your mailserver for those missing messages. either it reports an error (in which case you should get the error to your bounce address) or it reports the message as sent to the target server (in which case you tell your clients to check THEIR maillogs since you can prove you have sent the message)

Basic understanding of SMTP: mail from

I'm implementing an application in ruby on rails (although this is a minor detail) that needs to send emails. Everything works fine, but I'm surprised cause when the app sends a mail, as long as it's authenticated against the smtp server, the sender it's going to be whatever it's specified in mail from. My point is, I can authenticate in a smtp server with "myuser#mydomain.com" and "mypassword" and be able to send a mail in which the recipient would see whichever address I want as sender.
This doesn't make any sense for me, and I'm sure it can't be so easy. I know it's surely a completely silly question for most of you, but would really appreciate anyone could make it clear for me.
Cheers!!
You authenticate as a generic user, it is only an accident that your login name is similar to a mail address. And yes, usually you can send mail with any reverse-path (reverse-path is the address in the MAIL FROM SMTP command). This may be necessary, for example a list manager uses VERP and sends mails with many unique reverse-paths.
However, some mail servers and mail administrators do place restrictions on the reverse path and the address in the From header. Especially, if the server signs the message.
Moreover, if the receiving server checks SPF records, it is useless to impersonate a remote domain, even if it is allowed, because the mail will be rejected anyway (if the domain publishes an SPF DNS record).

Is there a reliable way to send email without having the senders smtp?

My application will be used in a manner that the user is remote from his computer running the application, receiving data via text messages sent periodically from the PC. Im sending the text message via email, using the number#carrierdomain.com. To simplify determining the user's smtp server, I've been sending the message using the destination phone carrier's smtp, instead of the whatever may or may not be available at the PC. This has worked so far with AT&T and T-Mobile, but not Verizon, as they have discontinued their smtp service.
I'm using mailsend v1.15 http://www.muquit.com/muquit/software/mailsend/mailsend.html
but Im open to alternatives.
I do have a less than ideal workaround, which is to use google or hotmail's smtp, but that requires a login/pass.
If I can send the text through regular email, using outlook, it works. I've looked at outlooks smtp logs, but that doesn't really help.
If its not being sent to a Verizon smtp server, how does it get routed, and is it something that my application can use?
Is there a reliable way to send email without having the senders smtp?
Theoretically, any smtp server can send your e-mail. However, due to the overwhelming amount of spaming on the internet, pretty much every isp has locked down their smtp server and will not allow anonymous relaying of e-mail.
If you do have the outlook client on the box you are sending the e-mail you can look at using one of the Outlook APIs:
http://msdn.microsoft.com/en-us/library/gg608200.aspx
to send the e-mail message. You are using the outlook configuration then and don't have to worry about it your code.
As long as an SMTP server is configured to allow relay from a remote domain then you can use it send email from/to virtually any address. There are downsides, however, to using any SMTP server to send an email from a specific domain - the most notable of which is that the recipient's domain will likely flag the message as spam because the domain of the SMTP server is different from that of the sender's email address.
There are other non-email APIs that can be used to send text messages, if that is something you're willing to consider. Check out:
Tropo (http://www.tropo.com)
Zeep Mobile (http://www.zeepmobile.com)
Best of luck to you.
Impossible. SMTP is the Simple Mail Transfer Protocol, without this is impossible to access to another account with Email format. You can make a php mail where you don't need to have smtp, but your access will be limited, not all ESP / ISP will allow you to delivery those emails, because they need to identify you using your SMTP and MX Lookup (Reverse MX A records) from your server. It exists more ways, but are 100% SPAMMERS and HACKERS methods and I don't recommend to use them.