本文介绍了使用C#将电子邮件发送到多个电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我设计了一个需要发送到多个地址的表单,这里是我必须将它发送给一个地址的代码。它还没有用,所以我只是将它循环到我自己进行测试。我如何为来自不同最终用户的多个地址编写代码。 protected void SendEmail( string toEmail, string ccEmail, int employeeDataId) { string from = " [email protected]" ; toEmail = " [email protected]" ; MailMessage message = new MailMessage (from,toEmail); message.Subject = "员工休假请求" ; message.Body = "员工请求时间已关闭。请点击以下链接访问他们的休假申请表。" + 环境 .NewLine + 环境 .NewLine; message.Body + = " http://.aspx?id =" + employeeDataId; SmtpClient mailClient = new SmtpClient ( "pv-exch01.pvsc.com" ); mailClient.Credentials = System.Net。 CredentialCache .DefaultNetworkCredentials; mailClient.Send(message); } 我有点被困在截止日期,请帮忙。 谢谢,Janis 解决方案 To MailMessage可以包含MailAddresses集合或逗号分隔的地址。使用以下代码 MailMessage message = new MailMessage(); ms.From = New MailAddress(from); //可以包含MailAddressCollection或逗号分隔的地址 ms.To.Add( " [email protected],second @ domain.com" ); I designed a form that needs to be sent to multiple addresses, here is the code that i have to send it to just one. It isn't live yet so I'm simply looping it to myself for testing purposes. How would I code it for multiple addresses coming from different end users. protected void SendEmail(string toEmail, string ccEmail, int employeeDataId){string from = "[email protected]";toEmail = "[email protected]";MailMessage message = new MailMessage(from, toEmail);message.Subject = "Employee Time Off Request";message.Body = "Employee has request time off. Please click on the following link to access their time off request form."+ Environment.NewLine + Environment.NewLine;message.Body += "http://.aspx?id=" + employeeDataId;SmtpClient mailClient = new SmtpClient("pv-exch01.pvsc.com");mailClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;mailClient.Send(message);}I'm Kinda stuck and on a deadline, please help.Thanks, Janis 解决方案 To of MailMessage can contain MailAddresses Collection or comma separated address. Use following codeMailMessage message = new MailMessage(); ms.From = New MailAddress(from); //To can contain MailAddressCollection or comma separated address ms.To.Add("[email protected], [email protected]"); 这篇关于使用C#将电子邮件发送到多个电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 17:47