如何使用 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 中附加多个文件。???
请给我解决方案。
...
mail.Body = txtComments.Text;
//Attach file
mail.Attachments.Add(new Attachment(txtAttachments.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments2.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments3.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments4.Text.ToString()));
SmtpServer.Port = 587;
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)