我正在尝试使用gmail的用户名和密码在
Windows应用程序中发送电子邮件.但是,当我在StringBuilder实例中收集多个电子邮件地址时,以下代码仅将邮件发送到第一个电子邮件地址.
var fromAddress = new MailAddress(username,DefaultSender); var toAddress = new MailAddress(builder.ToString());//builder reference having multiple email address string subject = txtSubject.Text; string body = txtBody.Text; ; var smtp = new SmtpClient { Host = HostName,Port = 587,EnableSsl = true,DeliveryMethod = SmtpDeliveryMethod.Network,UseDefaultCredentials = false,Credentials = new NetworkCredential(username,password),//Timeout = 1000000 }; var message = new MailMessage(fromAddress,toAddress) { Subject = subject,Body = body,IsBodyHtml = chkHtmlBody.Checked }; if (System.IO.File.Exists(txtAttechments.Text)) { System.Net.Mail.Attachment attechment = new Attachment(txtAttechments.Text); message.Attachments.Add(attechment); } if(this.Enabled) this.Enabled = false; smtp.Send(message);
我做错了什么,怎样才能解决我的问题?