Click here to Skip to main content
15,389,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I've added an email address in both TO and CC fields(same email in both textboxes). The recipient is getting two emails.

My tester is expecting only one mail, I tried removing the duplicate email from CC field. But my tester is expecting when he opens the ibox and see the TO and CC fields then he should see the email address in both TO and CC fields.

public ActionResult SaveSendNotification(SendNotificationCommonForAll dto)
                string[] CCList = { string.Empty };
                string[] ToList = { string.Empty };
                Guid guid = new Guid();

                UserDTO userDTO = (UserDTO)Session["UserDto"];
                string senderEmailId = userDTO.Email;
if (!string.IsNullOrEmpty(dto.SendNotificationCommon.ToRecipients))
                    ToList = dto.SendNotificationCommon.ToRecipients.Split(new[] { ';', ',' });
                    if (ToList.Contains(System.Configuration.ConfigurationManager.AppSettings["DLKey"]))
                        string allEmails = string.Empty;
                        foreach (string s in UserAccountService.GetUsersForMailSend(userDTO.CreatedBy).ToList())
                            if (s != "" || s != string.Empty)
                                allEmails = allEmails + s + ",";
                        ToList = allEmails.Split(new[] { ';', ',' });
                        ToList = ToList.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    foreach (string mail in ToList)
                        if (!IsValid(mail))
                            TempData["ResultMessage"] = "Invalid To mail: " + mail;
                            return RedirectToAction("Index", new { guid = guid, NotificationType = dto.SendNotificationCommon.NotificationType });
                    ToList = new HashSet<string>(ToList).ToArray();

                if (!string.IsNullOrEmpty(dto.SendNotificationCommon.CcRecipients))
                    CCList = dto.SendNotificationCommon.CcRecipients.Split(new[] { ';', ',' });
                    foreach (string mail in CCList)
                        if (!IsValid(mail))
                            TempData["ResultMessage"] = "Invalid Cc mail: " + mail;
                            return RedirectToAction("Index", new { guid = guid, NotificationType = dto.SendNotificationCommon.NotificationType });
                    CCList = new HashSet<string>(CCList).ToArray();
                CCList = CCList.Where(s => !string.IsNullOrEmpty(s)).ToArray();
                CCList= CCList.Except(ToList).ToArray();
                Email emaildetails = new Email(ToList, dto.HTMLEditor.HtmlContent, CCList, null, dto.SendNotificationCommon.Subject, Configurations.MailUser, new EmailConfiguration { HostName = Configurations.MailUser, ServerName = Configurations.MailServer, Password = Configurations.MailUserPassword, Port = Convert.ToInt16(Configurations.MailPortNumber) });
                SmtpClient smtpClient = new SmtpClient();
                MailMessage mailObject = new MailMessage();

                AdminSettingsDto AdminDTO = AdminSettingsCache.GetAdminsettingsFromCache();
                if (emaildetails.SendTo != null)
                    mailObject = PrepareMailMessage(emaildetails);
                    string smtpServerName = AdminDTO.SmtpServerName.Trim();
                    string userName = AdminDTO.Email;
                    string password = AdminDTO.Password;
                    NetworkCredential networkCredential = new NetworkCredential(userName, password);
                    smtpClient.Host = smtpServerName;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = networkCredential;
                    smtpClient.EnableSsl = Configurations.EnableSSL;
                    smtpClient.Port = (int)AdminDTO.Port;

                    //todo: needs to be uncommented on production

Thank you..

Ravikumar G.

What I have tried:

I've googled for this but didn't get any clues.
Updated 16-Mar-17 22:47pm
Graeme_Grant 17-Mar-17 2:57am
We can't see your code telepathically... Please share the code so we can see what you are doing.

Developers sacrifice and contribute their own time for free to help fellow developers resolve difficulties. It is important that you are crystal clear about what you are experiencing with plenty of information so that your time and theirs are not wasted. The clearer the question, the better chance that you will get a favorable response in a timely manner.

Please take the time to look at these links provided before posting questions:
* Some guidelines for posting questions in the forums[^]
* Tales from the Evil Empire - Asking questions is a skill[^]

Once you are ready update the question with clear and concise details, sample code, any error messages (includding inner exception details), etc, please click on Improve question to add more info to the question.
M,AqibShehzad 17-Mar-17 3:17am
post your code snippet
Graeme_Grant 17-Mar-17 3:24am
He's asked over 130 questions so far. You would think that he would know by now...

1 solution

Your tester does not know what he talks about. If you specify the same address multiple times, it will be send multiple times. It does not care in which of the destination fields ("To", "Cc", "Bcc") the address is specified. The SMTP server will parse all fields and forward the message to each listed recipient.

Mail clients will just show the content of the "To" and "Cc" destination fields. An address listed in the "To" field only will not be shown in the "Cc" field of the client.

Your tester should understand the purpose of those fields:

"To" is for the actual recipient(s) which might answer.

"Cc" is for additional recipients to get them informed but not expected to answer.

"Bcc" is like "Cc" but the field is removed from the mail (or modified) upon transmission.

See also section 3.6.3. Destination address fields of RFC 2822[^].

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