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

Dani AI

Generated

Good news that you got a local fix. As discovered, moving a message out of Spam trains that single Gmail account only. That helps recipients who do it, but it does not fix deliverability for other inboxes. was right to point toward server/domain-level causes — solving those is the reliable, long‑term approach.

Practical checklist to improve deliverability:

  • Make sure your domain and sending IP use proper authentication (SPF, DKIM) and a DMARC policy so receivers can report problems.
  • Ensure reverse DNS (PTR) for the sending IP matches your mail host and that your SMTP EHLO/HELO name is consistent with that PTR.
  • Keep envelope-from/Return-Path and the From header aligned to your sending domain so authentication checks pass.
  • For bulk or marketing mail include a List‑Unsubscribe header, visible unsubscribe text, and a physical contact address; avoid executable attachments and heavily obfuscated links.

Quick diagnostics and next steps:
Send a test to a Gmail account, open “Show original” and look at the Authentication‑Results, X‑Gm‑Spam/X‑Gm‑Phishy headers and the full Received chain to see what failed. Check your sending IP/domain reputation with reputation tools and enable DMARC aggregate reports to get real feedback. If you send a lot of mail or can’t get the IP reputation under control, move to a reputable transactional ESP or use Gmail’s official APIs/OAuth for authenticated sending.

Operational tips: keep a consistent From address, warm new IPs slowly, limit sudden large sends, and avoid spammy wording or huge image‑only emails. Manual fixes (marking not spam or adding to contacts) help individual recipients but don’t replace fixing authentication and reputation on the sending side.

Recommended Answers

All 2 Replies

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.