gpt4 book ai didi

c# - 使用C#在电子邮件中添加多个附件

转载 作者:太空宇宙 更新时间:2023-11-03 17:36:52 24 4
gpt4 key购买 nike

如何使用 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;
...

关于c# - 使用C#在电子邮件中添加多个附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1457940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com