Link to home
Start Free TrialLog in
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.
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

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);
Avatar of bmanmike39
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
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial