Avatar of bmanmike39
bmanmike39
 asked on

Invalid character @ error in my mail script. What is wrong with the Script ( ASP.NET C#)

I keep getting the following error when I run this code. what is wrong with the code.  

Error:
An invalid character was found in the mail header: '@'.

string bmsg = "<h3>" + txtFirstName.Text + " " + txtLastName.Text + "</h3>";
            bmsg += "<p>This is your EPIC IPCST Conference Ticket Number &nbsp;<strong>" + lbInvoiceNumber.Text + "</strong>&nbsp; please keep this for your records";

            string pt = "mypw";
            [b]string cr = "my@domain.com";[/b]
            MailMessage mm = new MailMessage(cr, emc);


            mm.Subject = "2015 Conference Ticket";
            mm.Body = bmsg;

            mm.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtpout.secureserver.net";
            smtp.EnableSsl = false;
            NetworkCredential NetworkCred = new NetworkCredential(cr, pt);
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 80;
            smtp.Send(mm);

Open in new window


ERROR:
An invalid character was found in the mail header: '@'.

Line 401 is where the error is coming form.
string cr = "my@domain.com";

Stack:
Line 400:            string pt = "mypw";
Line 401:            string cr = "my@domain.com";
Line 402:            MailMessage mm = new MailMessage(cr, emc);

Open in new window


Thank you.
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
Kyle Abrahams

8/22/2022 - Mon
Kyle Abrahams

string cr = "my@domain.com";
            MailMessage mm = new MailMessage(cr, emc);


what is EMC?
if you take out the cr and hardcode the string directly into it do you still get the error?

EG:
       MailMessage mm = new MailMessage("my@domain.com", emc);
bmanmike39

ASKER
emc contains the senders email address, also ours.  (sender@send.com, my@domain.com)

and yes, I still get the error.

This did work, But i don't know why or if it's safe or not.
string ourcopys = ", my@domain.com, deptHhead@domain.com";
MailMessage mm = new MailMessage(cr, emc + ourcopys);

Open in new window

Thank you!
ASKER CERTIFIED SOLUTION
Kyle Abrahams

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck