Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
web.config
XML
<appsettings>
  <add key="SMTP" value="my SMTP" />
  <add key="FROMEMAIL" value="myEmail address" />
  <add key="FROMPWD" value="pwd" />
  <add key="PORT" value="25" />
</appsettings>

Code behind using
C#
try
{
    string mFrom = From.ToString().Trim();
    string mTo = To.ToString().Trim();
    string mSubject = Subj.ToString().Trim();
    string mMsg = Msg.ToString().Trim();
    string mMailServer = ConfigurationManager.AppSettings.Get("SMTP");
    int mPort = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PORT"));
    MailMessage message = new MailMessage(mFrom, mTo, mSubject, mMsg);
    SmtpClient mySmtpClient = new SmtpClient(mMailServer, mPort);
    if (Bcc != "") 
    {
        message.Bcc.Add(Bcc);
    }
    // mySmtpClient.Credentials = new 
    // System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], 
    // ConfigurationManager.AppSettings["FROMPWD"]);
    //mySmtpClient.EnableSsl = true;
    message.Priority = MailPriority.High;
    message.IsBodyHtml = false;
    mySmtpClient.UseDefaultCredentials = true;
    mySmtpClient.Send(message);
    return true;
    }
catch (Exception ex)
{
    return false;
}


Why do my sent emails appear in spam/junk folder?

Kindly Reply
Posted
Updated 11-Apr-11 20:05pm
v3
Comments
Eduard Keilholz 12-Apr-11 2:06am    
Added some 'codeproject friendly' formatting

Email doensn't go to the spam/junk folder because of bad code, but because of bad mail content. You may want to test what happends if you remove the priority flag. Also your SMTP server may be black listed, which is also a common cause of email being flagged as spam.

Eduard
 
Share this answer
 
 
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