Answered by:
how to Add Recipient in SendEmail

Question
-
User-1009930070 posted
I have aspx page where i have one Email input field, How i can pass its value to my code in C#
private void SendEmail(int RefNum) { MailMessage ObjEmail = new MailMessage(); ObjEmail.From = "zjaff@hotmail.com"; ObjEmail.To = "zjaff@hotmail.com"; ObjEmail.Cc = Request["Email"]; }
I am getting error can you please tell me how i can do it.
Thanks
Monday, June 17, 2013 3:09 PM
Answers
-
User-718146471 posted
It should be (if memory serves me right)
ObjEmail.To.Add("primary@company.com");
ObjEmail.CC.Add("secondary@company.com");
ObjEmail.BCC.Add("tertiary@company.com");- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2013 3:47 PM -
User-1910946339 posted
If you comment out just the line which sets the CC do you receive mail? If you change the line which sets custEmail to
string custEmail = "jaffary_zafar@hotmail.com";
do you get the email? Try to narrow the problem down. Is it having a particular address for the CC that causes it to fail?
(I have to say - I don't understand the concept of a dev server that cannot be used for debugging! That seems a very strange definition of developmen)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2013 12:07 AM -
User-1695758799 posted
Code for reference,
private void SendEmail(int RefNum)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("projectallocationsystem@gmail.com", "Project Allocation System");
msg.To.Add(new MailAddress(txtTo.Text));
if (txtCC.Text != "")
{
msg.CC.Add(new MailAddress(txtCC.Text));
}
if (txtBCC.Text != "")
{
msg.Bcc.Add(new MailAddress(txtBCC.Text));
}
if (FileUpload1.PostedFile.ContentLength > 0)
{
var attachment = new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.PostedFile.FileName);
msg.Attachments.Add(attachment);
}
msg.Subject = txtSubject.Text;
msg.Body = Editor1.Content;
msg.IsBodyHtml = true;
SmtpClient setp = new SmtpClient();
setp.Host = "smtp.gmail.com";
setp.Port = 587;
setp.UseDefaultCredentials = true;
setp.Credentials = new NetworkCredential("projectallocationsystem@gmail.com", "*************");
setp.EnableSsl = true;
setp.Send(msg);
}- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2013 12:24 AM
All replies
-
User-718146471 posted
It should be (if memory serves me right)
ObjEmail.To.Add("primary@company.com");
ObjEmail.CC.Add("secondary@company.com");
ObjEmail.BCC.Add("tertiary@company.com");- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2013 3:47 PM -
User-718146471 posted
Argh, correction:
ObjEmail.To.Add(""); ObjEmail.To.CC("");
Take a look at this thread: http://stackoverflow.com/questions/2404577/net-system-mail-message-adding-multiple-to-addresses
Monday, June 17, 2013 3:48 PM -
User-2102145936 posted
Try this:
ObjEmail.CC.Add(emailid);
Hope it helps.
Monday, June 17, 2013 4:59 PM -
User-1910946339 posted
"Mr mechanic, my car doesn't work - tell me how to fix it?
It would be very hard for a mechanic to answer this question.
Could you tell us what the error is and which line causes it?
Monday, June 17, 2013 6:05 PM -
User-1009930070 posted
Thanks paul
I have one aspx page. where i have one input field
<input class="span12" type="text" placeholder="EMAIL" id="Email" name="Email" runat="server" />
on my aspx.cs page i want to pass Email value to SendEmail
private void SendEmail(int RefNum) { string custEmail = Request.Form["Email"]; MailMessage ObjEmail = new MailMessage(); ObjEmail.From = "jaffary_zafard@hotmail.com"; ObjEmail.To = "jaffary_zafard@hotmail.com"; ObjEmail.Cc = custEmail; ObjEmail.Subject = "Tournament"; //Development SmtpMail.SmtpServer = "torl.corp.ca"; //Production At Bell //SmtpMail.SmtpServer = "torl2.corp.ca"; ObjEmail.BodyFormat = MailFormat.Html; string strBody1 = "Thank you for registring Here are your Resgistration details:<br /><br /><b>Registration# Golf" + RefNum.ToString().PadLeft(3, '0') + "</b><br/><br/>Player1 Name: "; ObjEmail.Body = strBody1 + "Test Registration" ; ObjEmail.Priority = MailPriority.High; try{ SmtpMail.Send(ObjEmail); lblResponse.Text = "Thank you for sending the form !"; Response.AddHeader("Refresh", "2;URL=index.aspx"); } catch (Exception exc){ Response.Write("Send failure: " + exc.ToString()); } }
the CustEmail is the email address who enter in the aspx page, I want to get the email from aspx page and want to add in CC, so that when i will receive the email and copy of that email will also CC to that email. I tried but when i add for CC
string custEmail = Request.Form["Email"];
ObjEmail.Cc = custEmail;It does not work.
Thanks
Monday, June 17, 2013 10:39 PM -
User-1910946339 posted
"It does not work."
A little more detail would be helpful.
A compiler error? If so, what?
A runtime error? If so what?
Unexepcted behaviour? If so, what is expected and what happened?
Monday, June 17, 2013 10:42 PM -
User-1009930070 posted
//string custEmail = Request.Form["Email"]; MailMessage ObjEmail = new MailMessage(); ObjEmail.From = "jaffary_zafar@hotmail.com"; ObjEmail.To = "jaffary_zafar@hotmail.com"; //ObjEmail.Cc = custEmail;
if i comment these two lines then i get email, But when uncomment even i am not getting email at all.
thanks paul
Monday, June 17, 2013 10:50 PM -
User-1910946339 posted
If you put a breakpoint on the
ObjEmail.Cc = custEmail
line. What is the value of custEmail?
Monday, June 17, 2013 10:52 PM -
User-1009930070 posted
I can not run in debug it is on dev server and there other many projects. i tried on my home pc but it does not allowing me without that environment, The information i gave you , you would not be able to guide me.
thanks
Monday, June 17, 2013 11:46 PM -
User-1910946339 posted
If you comment out just the line which sets the CC do you receive mail? If you change the line which sets custEmail to
string custEmail = "jaffary_zafar@hotmail.com";
do you get the email? Try to narrow the problem down. Is it having a particular address for the CC that causes it to fail?
(I have to say - I don't understand the concept of a dev server that cannot be used for debugging! That seems a very strange definition of developmen)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2013 12:07 AM -
User-1695758799 posted
Code for reference,
private void SendEmail(int RefNum)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("projectallocationsystem@gmail.com", "Project Allocation System");
msg.To.Add(new MailAddress(txtTo.Text));
if (txtCC.Text != "")
{
msg.CC.Add(new MailAddress(txtCC.Text));
}
if (txtBCC.Text != "")
{
msg.Bcc.Add(new MailAddress(txtBCC.Text));
}
if (FileUpload1.PostedFile.ContentLength > 0)
{
var attachment = new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.PostedFile.FileName);
msg.Attachments.Add(attachment);
}
msg.Subject = txtSubject.Text;
msg.Body = Editor1.Content;
msg.IsBodyHtml = true;
SmtpClient setp = new SmtpClient();
setp.Host = "smtp.gmail.com";
setp.Port = 587;
setp.UseDefaultCredentials = true;
setp.Credentials = new NetworkCredential("projectallocationsystem@gmail.com", "*************");
setp.EnableSsl = true;
setp.Send(msg);
}- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2013 12:24 AM