Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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).

C#
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

What I have tried:

C#
MailAddress bcc = new MailAddress(&quot;example@gmail.com&quot;);
            m.Bcc.Add(bcc);
Posted
Updated 8-Nov-16 0:39am
Comments
Animesh Datta 8-Nov-16 2:31am    
how do you know that BCC mail is not going ? does your bcc emailid exists ?
Bigprey 8-Nov-16 3:55am    
I don't receive the BCC mails. It's one of my own email id and it does exist.
F-ES Sitecore 8-Nov-16 5:26am    
Talk to whoever owns the smtp server, they might have disabled bcc. Might also be worth checking the gmail account can receive bcc emails and they are not in your spam folder.
Bigprey 8-Nov-16 6:34am    
@F-ES Sitecore You are right... Only the Gmail's BCC are not allowed. I thought since "To" addresses including some gmail ids are going fine, then it should also accept BCC. Anyway, I only thought of knowing how the mail gets shown up in gmail. So, I can't find it through BCC method.

Thanks mate for your help.

Your code looks good, so I would suggest that the bug is either in the MailMessage object, or in your e-mail server. You could track down which one by:

1. Connect to your e-mail server using an existing e-mail client (thunderbird or similar). Send a message with a BCC, and see if the server actually sends it off.

2. Save your e-mail to a file. There is a reasonable article here (Adding Save() functionality to System.Net.Mail.MailMessage[^]) to show how to do that. Make sure the BCC headers are there.
 
Share this answer
 
I found the issue.

Only the Gmail is not accepting BCC. I thought since "To" addresses has some including gmail ids & receiving mails, 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.
 
Share this answer
 
v2
Comments
Midi_Mick 8-Nov-16 8:58am    
How DARE they! I'd not have picked that as an option. I guess to see it, you'll need to make a copy of the message and send it to Gmail as the only recipient. However, I reiterate, how DARE they!
Bigprey 8-Nov-16 23:55pm    
Since they are limiting a lot such as how the images are shown in the Emails strictly, I too thought of getting a copy of the each mails through a BCC to my own Gmail. But's its not allowed, it seems. Anyway, thanks

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