C# Outlook正文的迭代数组
这就是我试图使用的代码。但它实际上并没有像我所希望的那样迭代数组来填充主体。我想做的是使用C#创建一封outlook电子邮件,填充收件人、邮件主题,然后根据数组中包含的内容生成电子邮件正文。编辑-我移动了for-each循环,试图用数组的每个元素填充主体,但我得到一个编译错误,即无法使用此代码将int转换为stringC# Outlook正文的迭代数组,c#,arrays,outlook,C#,Arrays,Outlook,这就是我试图使用的代码。但它实际上并没有像我所希望的那样迭代数组来填充主体。我想做的是使用C#创建一封outlook电子邮件,填充收件人、邮件主题,然后根据数组中包含的内容生成电子邮件正文。编辑-我移动了for-each循环,试图用数组的每个元素填充主体,但我得到一个编译错误,即无法使用此代码将int转换为string public static string GenerateEmail() { try { for (int q = eName.Get
public static string GenerateEmail()
{
try
{
for (int q = eName.GetLowerBound(0); q <= eName.GetUpperBound(0); q++)
{
return Global.Variables.GlobalVariables.eName[q];
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
for (int q = eName.GetLowerBound(0); q <= eName.GetUpperBound(0); q++)
{
oMsg.HTMLBody = q;
}
oMsg.Subject = "Reports Are Ready";
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("123123123@testemail.com");
oRecip.Resolve();
oMsg.Save();
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}
}
catch
{
}
return null;
}
}
public静态字符串GenerateEmail()
{
尝试
{
for(int q=eName.GetLowerBound(0);qfor
循环中的第一行似乎是一个返回语句,这会导致函数的立即缩写
如果要填充邮件正文而不是为每个交互创建一封邮件,请将实际电子邮件的声明移到循环外部。然后在循环内部将内容附加到邮件中:
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
string content = string.Empty;
for (int q = eName.GetLowerBound(0); q <= eName.GetUpperBound(0); q++)
{
content += "...";
}
oMsg.HTMLBody = content;
// additional settings
Outlook.Application oApp=新建Outlook.Application();
Outlook.MailItem oMsg=(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
string content=string.Empty;
for(int q=eName.GetLowerBound(0);q在循环中的第一个语句中返回,空捕获???您想做什么?通常,一个良好的旧的逐步调试会话将为您节省大量的时间和精力…标题已编辑,您有C#标记,它不需要在标题中。我想用数组中包含的所有元素填充单个电子邮件的正文。删除返回行(您建议的第1行代码)现在为数组的每个元素创建一封新电子邮件,而不是用每个元素填充1封电子邮件的正文。