如何发送带有附件的电子邮件? [英] how to send email with attachments?
问题描述
你好,我有这段代码可以从Windows窗体应用程序发送电子邮件,它可以与一个附件一起正常工作,但是我不能让它与一个以上附件一起运行
Hello I have this code for sending emails from windows form app,and it works fine with one attachment, but I cant get it to run with more then one attachment
mail.From = new MailAddress(Main.ml.Text);
mail.Subject = subject.Text;
mail.Body = message.Text;
foreach (string s in to.Text.Split(';'))
{
mail.To.Add(s);
}
foreach (Attachment attach in attachment.Text.Split(';'))
{
mail.Attachments.Add(attach)
}
{
mail.To.Add(s);
}
mail.Headers.Add("Disposition-Notification-To", Main.ml.Text);
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient client = new SmtpClient(Main.smtp.Text);
client.Port = 25;
client.Credentials = new System.Net.NetworkCredential(emailusername.Text, emailpassword.Text);
client.EnableSsl = true;
client.Send(mail);
并且在那段突出显示的代码上出现错误(无法将类型字符串转换为system.mail.attachment),我的意思是它不起作用,只能与一个附件一起使用,但是我不知道如何获取多个
添加了代码块[/编辑]
and I get error (cannot convert type string to system. mail.attachment )on that piece of highlighted code, I mean it doesnt work, it works with one attachment, but I dont know how to get multiple
Code block added[/Edit]
推荐答案
在这里看看: ^ ]
您好,
试试
Hello,
Try
mail.Attachments.Add(new Attachment(attach));
看到这里:
http://msdn.microsoft.com/en-us/library/56wesadc.aspx [ ^ ]
瓦莱里.
see here:
http://msdn.microsoft.com/en-us/library/56wesadc.aspx[^]
Valery.
以下是除 ^ ] ..
http://stackoverflow.com/questions/2825950/send-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunde [ http://csharp.net-informations.com/communications/csharp-email-attachment.htm [^ ]
Below are 2 examples other than this Code Project one[^]..
http://stackoverflow.com/questions/2825950/sending-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunde[^]
http://csharp.net-informations.com/communications/csharp-email-attachment.htm[^]
这篇关于如何发送带有附件的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!