Click here to Skip to main content
15,891,770 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,

please Correct the Code. This if form
ASP.NET
<asp:TextBox ID="txtEmail" runat="server" CssClass="textEntry" Text='<%# Bind("EmailId") %>'>

this is web.config.
XML
<appsettings>
   <add key="UserCode" value="101010" />
   <add key="ReceiverMailId" value="xxxxx@gmail.com" />
   <add key="EmpCC" value="EmailId" />
 </appsettings>

this is CS
C#
try
            {
                SmtpSection sec = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
                string Host = sec.Network.Host;
                int Port = sec.Network.Port;
                string From = sec.From;
                mailMsg.From = new MailAddress(From);

                mailMsg.To.Add(ConfigurationManager.AppSettings["ReceiverMailId"].ToString());
                mailMsg.CC.Add(ConfigurationManager.AppSettings["EmpCC"].ToString());
                mailMsg.Body = "Please find the attached details of Employee " + empCode;
                mailMsg.Subject = "Tax Saving Proposal details for " + empCode;
                mailMsg.IsBodyHtml = true;

                var fileName = HttpContext.Current.Server.MapPath(@"~/EmpReports/" + empCode + ".PDF");
                string AttachmentName = fileName;
                Attachment att = new Attachment(AttachmentName, "application/pdf");
                att.Name = empCode + "  Details";
                att.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;
                mailMsg.Attachments.Add(att);

                SmtpClient smtp = new SmtpClient(Host, Port);
                NetworkCredential netCred = new NetworkCredential(sec.Network.UserName, sec.Network.Password);
                smtp.Credentials = netCred;
                smtp.Send(mailMsg);
            }

Errot Message not getting and noc me to mail CC
Posted
Updated 7-Jun-12 17:01pm
v2

1 solution

C#
1. mailMsg.CC.Add(ConfigurationManager.AppSettings["EmpCC"].ToString());
2. <add key="EmpCC" value="EmailId" />
3. Text='<%# Bind("EmailId") %>

Based on following three, it's clear that the way you are trying to use EmailId field is incorrect. Hence, the cc field is not correctly populated to get an email.

Your 'cc' field is getting data from a grid so you need to pull from there instead of forcefully using(copy-paste 'to' logic!) Web.Config.
If you have a grid Ui where every row has some button to send an email then use the grid row to get the 'cc' email id and use it in code. Or else track the email id any other way to pass on to email method. Web.config method is surely not the way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900