我在我的电子邮件中添加了一个密件抄送字段,并且在主题行中收到错误。一切工作正常,当我注释出BCC线,所以我不知道什么是错的。这里是我使用的代码(这是在Delphi .NET但主要是一样的C#和VB):我已经试过玩弄使用MailAddress和MailAddressCollection代替,但仍然收到了同样的错误将邮件地址添加到.net邮件时,指定的字符串不是电子邮件地址所需的格式
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;
。当我调试它,通过的PARAMS是:
SendEmail([email protected], [email protected], [email protected], [email protected], Thanks for registering, Some Body Text);
正如你所看到的,CC和BCC的电子邮件地址是相同的,但是当线就在那里我只得到一个错误。
编辑:堆栈跟踪的部分:
[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
没有人有任何想法,为什么是这样?
它是抱怨或组件的服务器? – 2010-10-01 08:20:35
我相信这是组件。堆栈跟踪停止在我发布的SendEmail方法 - 我已经将部分堆栈跟踪添加到OP。 – webnoob 2010-10-01 08:27:11