hello every one

im trying to send Email using ASP.NET with C#
but when recieved it is marked as spam
this is a problem...

i searched alot and almost i put every thing to avoid marking my emails as spam..but all didn't work

this is the piece of code i use

MailMessage mail = new MailMessage();
        mail.To.Add(new MailAddress(ToMail));
        mail.From = new MailAddress(FromMail);
        mail.Subject = txtSubject.Text;

        string Body = txtContent.Value;
        mail.Body = Body;
        mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
        mail.IsBodyHtml = true;

        AlternateView plainView = AlternateView.CreateAlternateViewFromString
(System.Text.RegularExpressions.Regex.Replace(Body, @"<(.|\n)*?>", string.Empty), null, "text/plain");
        System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

        mail.AlternateViews.Add(plainView);
        mail.AlternateViews.Add(htmlView);

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             (FromMail , Password);
        //Or your Smtp Email ID and Password
  
        smtp.EnableSsl = true;
        smtp.Send(mail);
   
        txtContent.Value = "";
        txtSubject.Text = "";

waiting ur replies..
thnks in advance

Sometimes is not a PHP / Script problem. Is your server properly configured? not blacklisted ? using SPF records?

Are you using your own smtp or trying to send using a remote server / relaying (major issue).

In the scripting side some headers may help but I'm not used to ASP / .NET

Try sending the email again to one of your accounts at gmail / hotmail / etc and see why it was marked as spam, that will give you some hints about what to change / add.

Hello again..
after searching and asking some people who worked with sending emails before , i found that the code provided above is enough ..
and the problem can be solved by just opening ur email used to recieve the emails and mark the spam email as not spam

then all other emails will reach directly to ur inbox
i tried it and it really worked..

thanks alot for all
now it is solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.