Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to send mail using SmtpClient and MailMessage object. Mail is being set succesfully but going to SPAM and not in inbox. Please suggest me what to add more here in my code.

here is my code..
public void SendMail(string from, string pwd ,string to)
   {
       try
       {
           SmtpClient smtp = new SmtpClient();
           smtp.Host = "smtp.gmail.com";
           smtp.Port = 587;
           smtp.EnableSsl = true;
           smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
           smtp.Credentials = new System.Net.NetworkCredential(from, pwd);

           MailMessage Msg = new MailMessage(from, to, "Demo Mail", txtStfComments.Text);
           Msg.IsBodyHtml = false;
           smtp.Send(Msg);
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }


i am calling this function on click event of a button.

Edit: removed sensitive information.
Posted
Updated 18-Jan-14 1:47am
v2
Comments
Richard MacCutchan 18-Jan-14 7:34am    
Sending a mail message with "hacker" in the username will send every Mail system crazy. No wonder it goes to the Spam box.

BTW publishing your username and password is not a sensible thing to do.
Mitchell J. 18-Jan-14 7:47am    
Totally agree.
[no name] 19-Jan-14 23:44pm    
the password i displayed in my question was not correct.
Bernhard Hiller 20-Jan-14 9:18am    
Do you understand on which side the classification as "spam" happens?
Any spammer would be gald it was the sender, then he could send as much spam as he wanted.

1 solution

It's not the code that causes this: it's the content, or address it comes from.

It could be the subject, the message in your email, or links - anything can trigger a spam filter.

Change the message and see if that helps.
 
Share this answer
 

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

  Print Answers RSS


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