0

In one of my asp.net pages (C#), I am using a SMTP mail option. Everything works fine in the mail such as subject, To addresses, etc., except for the BCC to a default gmail address (I use this to verify how the mail end up at others mailbox).

protected void SendEmail(string MemberName, string EmailId)
{
    string TextMessage = TBMessage.Text;
    string ClubName = TBClubName.Text;
    string HtmlTemplate = Server.MapPath("EmailTemplates/PromoteMembers.html");
    string content;
    string senderID = "promote@example.com";
    const string senderPassword = "p@ssw0rd";             
    using (var strReader = new StreamReader(HtmlTemplate))
    {
        content = strReader.ReadToEnd();
    }
    using (StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {                                        
            content = content.Replace("<%Name%>", MemberName);
            content = content.Replace("<%Message%>", TextMessage);                    
        }
    }
    string HtmlBody = content;
    AlternateView alternateView = AlternateView.CreateAlternateViewFromString(HtmlBody, null, "text/html");                       
    MailMessage m = new MailMessage();
    m.AlternateViews.Add(alternateView);
    m.From = new MailAddress(senderID, "example.com");
    m.To.Add(new MailAddress(EmailId, MemberName));
    m.Subject = "Message from " + ClubName;
    MailAddress bcc = new MailAddress("example@gmail.com");
    m.Bcc.Add(bcc);
    SmtpClient smtp = new SmtpClient
    {
        Host = "mail.example.com",
         Port = 8889,
        EnableSsl = false,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
        Timeout = 3000000,
    };            
    smtp.Send(m);
}

Kindly let me know the mistake I am doing here. Thanks in advance

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
Prem kumar
  • 21
  • 6

1 Answers1

0

I found the issue.

Only the Gmail is not accepting BCC. I thought since "To" addresses has some including gmail ids, then it should also accept BCC.

Anyway, I only thought of knowing how the mail gets shown up in other's gmail inbox. So, I can't find it through BCC method.

Prem kumar
  • 21
  • 6