How to check if the mail has been sent successfully

Hi All

I am developing an OnBoarding App in unity, where I am sending a mail to the user’s email address, if he forgets the password.I want to check if the mail has been sent sucessfully or not. Is there any method to
know that for sure.In case if an email id does’nt exists, then would I detect a failure.

I am using this below code. For Sending mail

     using (var mail = new MailMessage
            {
                From = new MailAddress(sender),
                Subject = " Password     " + PlayerPrefs.GetInt("PPI_Passcode"),
                Body = "Password is  " + PlayerPrefs.GetInt("PPI_Passcode")


            })
                            try{
                    mail.To.Add(receiver);
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                }
                catch (Exception ex){


                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    Debug.Log("error");
                }

          
                Debug.Log("The Mail Delivered are "+mail.DeliveryNotificationOptions);

                var smtpServer = new SmtpClient(smtpHost)
                {
                    Port = 25,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    EnableSsl = true,
                    UseDefaultCredentials = false,

                    Credentials = (ICredentialsByHost)new NetworkCredential(sender, smtpPassword)
                };
                ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                try
                {
                    smtpServer.Send(mail);
                              mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

                }
                catch (Exception ex)
                {
                            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                 Debug.Log("ERROR ");
                }

            }

But Mail.DeliveryNotificationOptions is not working. I am using Gmail from Sending mail.

Catch Sometimes working. Some times not…So is there any way to find the mail has been reached the user or not.

Some times the user may give wrong id. So at the time i have to inform the id is wrong. Is there any way to do it?

Short of using some frowned upon, spammy ‘hidden invisible pixel’ methods - no. The SMTP protocol does not mandate a receipt, much less a read receipt. Some mail Servers may send a bounce or no address notification, but this is becoming less common, as it is a common way to try to find valid email addresses for spamming/phishing purposes.
Many providers actively shield their customers from this kind of privacy Invasion, and if they detect your application trying to do that, this will result your app/Service in being blacklisted. Never, ever, try to track your customers without their explicit consent (plus, when you are in the EU, you’d be half way down to receiving a fine).

[Edit] What you can and should do is provide a one-time link in your email that the user can click on to verify that they read the email. This leaves it up to the customer to decide if they want to confirm receipt or not. On the receipt screen you then show the new Password. This prevents the new Password being intercepted (mail is sent as clear text) and provides an additional layer of security (although, truth be told, if the attacker can intercapt the text mail, they can also intercept the one-time link. The one-time link has the only Advantage that it tells you if multiple People have accessed it).

Thanks csofranz … for your reply… I just have stopped the mail verification of the user sent or not.
I have another question. While sending mail from unity. the unity takes 10 seconds for sending mail.
That time it strucks… ( i know smtp takes times for sending mail).

Is there any way to reduce the strucks…without takes much times… The mail should send…

I’m sorry, but I don’t know what ‘strucks’ are. Can you explain?

Strucks means … It takes max 1 minutes time to send email. That times i cant do anything. Immediately i have to send mail… is there any way…

Do I understand you correctly that your app is waiting for the sendmail process to return control to you, and that therefore your entire app is frozen?

Why don’t you send the email using a coroutine or spawn a separate process for that?

-ch

abs correct…

i think coroutine also do the same. I will try… how can i spawn a separate process for that…

A good starting Point for threads is here. Just make sure you do not call any Unity API methods, as they are not thread safe, but the rest should work well.

And if you know threads, here’s the doc to some c# exaple from MS

Thank csofranz for you post… your post helped you so much. Thanks… i will update my changes…

I have found a solution.

smtpServer.Send(mail);

I  changed this code to 
smptServer.SendAsync(mail,"success");

mail is working fast without strucking…