Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

As we send a auto generated mail to user. through our code. let us consider receiver emailid is of Gmail. then receiver have enable to receive a mail from those mails send from system i.e system or code generated. if they do not have set allow to it then mail sending is failure. How to avoid this. what should I do to send mail without rejected by client/user mail server.

please help.

What I have tried:

C#
using (MailMessage mm = new MailMessage("trial@gmail.com", trialEmail.Text))
    {
        mm.Subject = "Send test";
        string body = "Hello " ;
        mm.Body = body;
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential("trial@gmail.com", "password");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
    }



Google Account Security

Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.

Note, there is no longer an "application specific" section.


once I do this setting in receiver mail account then I able to send mail. but problem is it is by default block/off . and most of user don't make it on. bit it was surprising we got a mails from amazon or facebook sites without enabling this setting. What they do for it?
Posted
Updated 12-May-16 14:31pm
v3

You can't avoid it.

The settings of the recipient side of an email are completely out of your control. There is no way for your email to get around that. Whether or not the recipient wants to receive the email is entirely up to them and the email client and email server settings.
 
Share this answer
 
Comments
Kishor-KW 12-May-16 17:33pm    
Then how can we got a mails from amazon,facebook,even from our code project, is it the case that we have to write other code for it. to make our email id get into the so called safebox to them
Dave Kreskowiak 12-May-16 17:52pm    
You don't do anything. Emails, by default, are considered good until someone tells either the email client or the email servers transferring the emails that they are bad, either by email content or by sender.
Kishor-KW 12-May-16 17:55pm    
then why we need to enable this setting in google security? and after this we able to send mail through our code.before that we just can't
Dave Kreskowiak 12-May-16 19:56pm    
That is a function of your Google mail account on Googles mail servers, NOT of your code.
Why was is it rejected? This reason drives what you can do. If it was rejected because of an unknown or invalid email address. Then you could attempt to validate you have the right email or see if there is a spelling mistake.

But if the rejection is because your mail server or domain has been blacklisted not much you cam do except contact the owner of the server.
 
Share this answer
 
Comments
Kishor-KW 12-May-16 17:14pm    
Google Account Security

Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.

Note, there is no longer an "application specific" section.


once I do this setting in receiver mail account then I able to send mail. but problem is it is by default block/off . and most of user don't make it on.
I found the answer it's pretty simple.

add smtp.UseDefaultCredentials = true;
before NetworkCredential line
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900