Hi All,
I have added a bcc field to my email that I am sending out and getting the error in the subject line. Everything works fine when I comment out the BCC line so I am not sure what is wrong. Here is the code I am using (it is in Delphi .NET but the principal is the same as C# and VB):
procedure TEmail.SendEmail(From, SendTo, CC, Subject, Body, BCC: String; Html: Integer);
var
Mail: MailMessage;
Smtp: SMTPClient;
begin
Mail := MailMessage.Create(From, SendTo);
Smtp := SMTPClient.Create;
if CC <> '' then Mail.CC.Add(CC);
if BCC <> '' then Mail.Bcc.Add(BCC);
Mail.Subject := Subject;
Mail.Body := Body;
if Html = -1 then Mail.IsBodyHtml := True else Mail.IsBodyHtml := False;
Smtp.DeliveryMethod := SmtpDeliveryMethod.PickupDirectoryFromIis;
try
Smtp.Send(Mail);
except
Smtp.DeliveryMethod := SmtpDeliveryMethod.Network;
try
Smtp.Send(Mail);
except
raise;
end;
end;
end;
I have tried playing around using MailAddress and MailAddressCollection instead but still recieve the same error. WHen I debug it, the params passed through are:
SendEmail([email protected], [email protected], [email protected], [email protected], Thanks for registering, Some Body Text);
As you can see, the CC and BCC email addresses are the same but I only get an error when the Mail.Add.Bcc
line is in there.
EDIT: Part of the Stack Trace:
[FormatException: The specified string is not in the form required for an e-mail address.]
System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) +1296
System.Net.Mail.MailAddressCollection.ParseValue(String addresses) +102
Does anyone have any ideas why this is the case?