如何使用c#在電子郵件中附加多個文件。使用C#的電子郵件中的多個附件文件
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
//get the userID, Pass
userID= register.userName;
password = register.pass;
string aa=txtTo.Text;
mail.From = new MailAddress(userID);
mail.To.Add(aa);
mail.Subject = txtsubject.Text;
mail.Body = txtComments.Text;
//Attach file
mail.Attachments.Add(new Attachment(txtAttachments.Text.ToString()));
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(userID, password);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("Email sent successfully");
this.Cursor = Cursors.Default;
//close the page
Email email = new Email();
email.Close();
此代碼僅用於附加一個文件。我如何在C#2008中附加多個文件? Plz給我解決方案。
任何完整的源代碼示例? – Kiquenet 2013-08-19 11:34:25
@David如何才能添加動態數量的附件? – NuWin 2016-09-09 16:33:09