System.FormatException:指定的字符串不是电子邮件地址所需的格式。 [英] System.FormatException: The specified string is not in the form required for an e-mail address.
问题描述
您好我从我的数据库向客户发送电子邮件时收到此错误:
Quote:System.FormatException:指定的字符串不是电子邮件地址所需的格式。在System.Net.Mime.MailBnfHelper.ReadMailAddress(字符串数据,的Int32&安培;偏移,字符串&安培;显示名)在System.Net.Mime.MailBnfHelper.ReadMailAddress(字符串数据,的Int32&安培;偏移)在System.Net.Mail.MailAddressCollection.ParseValue (字符串地址)在System.Net.Mail.MailAddressCollection.Add(字符串地址)在Admin_newsletter.HtmlEmailTemplate()中d:\hosting\9780189\html\Admin\\\
ewsletter.aspx.cs:线143
这是我用来向所有客户发送电子邮件的代码:
< pre lang =cs> string [] recipients = new [] { teke@gmail.com, dan.jojo@gmail.com};
DataTable dt = _UserInfo.GetUserAllByEmail();
string bccAddresses = ;
string 地址= ;
mailMessage.From = new MailAddress( sales@gmail.com, 我们为您提供大优惠!);
mailMessage.To.Add( dan@gmail.com);
foreach (DataRow drRecipient in dt.Rows)
{
bccAddresses = bccAddresses + <跨度类= 代码串> 跨度> <跨度类= 代码串 > 跨度> + drRecipient [<跨度类= 代码串> 电子邮件]。ToString()+ , 跨度>;
地址= bccAddresses.TrimEnd(' ,');
}
mailMessage.Bcc.Add(地址);
mailMessage.Subject = 测试电子邮件;
mailMessage.IsBodyHtml = true ;
这是我的查询:
ALTER 程序 [dbo]。[GetUserByEmail]
AS
BEGIN
SELECT U.UserName as 电子邮件来自 [用户] U
left join [Member] M on M.UserId = U.UserId
END
如果你想知道的价值地址,这里是:muhi @ gmail.com,josh @ hotmail.com,ihope031 @ gmail.com
和第143行: mailMessage.Bcc.Add(地址);
有人能帮助解决这个问题。这是在某处你的字符串连接,这是没有必要的。
foreach (DataRow drRecipient in dt.Rows )
{
mailMessage.Bcc.Add(drRecipient [ Email]的ToString());
}
Hi I am getting this error while sending an email to clients from my db:
Quote:System.FormatException: The specified string is not in the form required for an e-mail address. at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset) at System.Net.Mail.MailAddressCollection.ParseValue(String addresses) at System.Net.Mail.MailAddressCollection.Add(String addresses) at Admin_newsletter.HtmlEmailTemplate() in d:\hosting\9780189\html\Admin\newsletter.aspx.cs:line 143
This is the code am using to send an email to all clients:
string[] recipients = new[] { "teke@gmail.com", "dan.jojo@gmail.com" };
DataTable dt = _UserInfo.GetUserAllByEmail();
string bccAddresses = "";
string Address = "";
mailMessage.From = new MailAddress("sales@gmail.com", "We have big Deals for you!");
mailMessage.To.Add("dan@gmail.com");
foreach (DataRow drRecipient in dt.Rows)
{
bccAddresses = bccAddresses + " " + drRecipient["Email"].ToString() + ",";
Address = bccAddresses.TrimEnd(',');
}
mailMessage.Bcc.Add(Address);
mailMessage.Subject = "Test Email";
mailMessage.IsBodyHtml = true;
And this is my query:
ALTER PROCEDURE [dbo].[GetUserByEmail]
AS
BEGIN
SELECT U.UserName as Email from [User] U
left join [Member] M on M.UserId=U.UserId
END
in case u want to know the values of Address, here it is: muhi@gmail.com, josh@hotmail.com, ihope031@gmail.com
And the line 143 it is:
mailMessage.Bcc.Add(Address);
Can someone help fixing this issue.
It's somewhere in your string concatenation, which is not needed at all.
foreach (DataRow drRecipient in dt.Rows) { mailMessage.Bcc.Add(drRecipient["Email"].ToString()); }
这篇关于System.FormatException:指定的字符串不是电子邮件地址所需的格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!