c# - 如何在mailbee LoadMessage的路径中进行连接
问题描述
这是我用来从带有扩展名的文件夹中获取所有名称的代码
string[] files = Directory.GetFiles(@"D:\DLogs\Notification11");
foreach (string file in files)
{
//Console.WriteLine(Path.GetFileName(file));
listOfFiles.Add(Path.GetFileName(file));
mailBeeTask(listOfFiles);
}
现在的问题是,在 mailBeeTask(listOfFiles) 我给出的文件名带有扩展名,但 mailbee 使用
mailer.Message.LoadMessage(@"D:\DLogs\Notification11\mailbee.eml");
这是mailbee代码
public static void mailBeeTask(IList<string> ListOfTasks)
{
//send emails
Smtp mailer = new Smtp();
// Use SMTP relay server with authentication.
mailer.SmtpServers.Add("smtp.domain.com", "joe@domain.com",
"secret");
// Load the message from .EML file (it must be in MIME RFC2822
format).
mailer.Message.LoadMessage(@"D:\DLogs\Notification11\mailbee.eml");
**//this above line is the problem, how can i use ListOfTasks
instead
//of mailbee.eml should i concatenate or what??**
// Demonstrate that we can modify the loaded message.
// Update the date when the message was composed to the current
moment.
mailer.Message.Date = DateTime.Now;
mailer.Send();
}
Mailbee 用于发送 afterlogic 制作的电子邮件。
解决方案
根据逻辑,您希望发送给定目录中的所有消息文件。因为单个文件本身就是一条完整的消息,所以您必须单独发送每个文件/消息。
您正确获取了所有文件。但是你必须mailBeeTask
为每个文件执行。
所以 for each 中的两行会得到
mailBeeTask(file);
并且签名mailBeeTask
必须更改为
public static void mailBeeTask(string filename)
其次是使用上次更改中的参数
mailer.Message.LoadMessage(filename);
您的代码现在将遍历指定目录中的所有文件,然后将mailBeeTask
使用完整文件名作为参数调用该方法。然后该方法加载单个文件,修改日期并发送它。
使用 OP 中的给定代码,您还将遭受以下痛苦:您首先将文件添加到列表中listOfFiles
,然后mailBeeTask
为列表中的每个文件执行。在下一次迭代中,这会导致列表中的所有先前文件再次作为参数提供。使用已经工作的代码,您将在一次迭代中发送所有先前的文件和当前文件。
推荐阅读
- c++ - 如何修复leetcode中的“运行时错误:引用绑定到'value_type'(stl_vector.h)类型的空指针”?
- html - 在加载程序中显示百分比
- php - 使用 AWS for PHP 为 Amazon Comprehend 创建客户端
- c# - 如何在考虑速率限制的同时删除频道中的所有消息?
- javascript - 水平步进式破碎机
- c# - Webapi inherited controllers are ignoring Route attributes
- wordpress - 无法缓存 .htaccess 文件中的文件
- c++ - 多网络连接的线程与异步 I/O
- email - Norifications:: 不传递特定数据但使用数组
- jenkins - 运行通过 WAR 文件创建的 Jenkins 服务时更改端口