AX 2009 实现outlook发送邮件并带多个附件
做过AX的人,对outlook发送邮件都应该非常熟悉,但是,要将AX中的附加图片和文档,一起附加到outlook并发送。我觉得还是值得一说的。
我还是以拿出代码和大家分享吧。
void sendEmail()
{
COM outLook;
COM item;
COM attach;
COM cc;
System.Net.Mail.MailAddress adrSend;
str subPath;
str strSubject;
str userid;
int i;
System.Text.RegularExpressions.Regex reg;
EmplTable emplTable; ;
userid = curuserid();
emplTable = EmplTable::find(EmplTable::userId2EmplId(curuserid()));
//reg = new System.Text.RegularExpressions.Regex("@^\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*$/"); reg = new System.Text.RegularExpressions.Regex("^[/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+$");
if(!reg.IsMatch(emplTable.OutlookUserID))
{
throw error("Email format is error");
} //adrSend = new System.Net.Mail.MailAddress(emplTable.OutlookUserID);
adrSend = new System.Net.Mail.MailAddress("kui.ding@rogrand.com");
outLook = new COM("OutLook.application");
item = outLook.CreateItem(0);
attach = item.attachments();
//item.to(emplTable.OutlookUserID);
item.to("364991746@qq.com");
//item.cc("kui.ding@rogrand.com;kimding@163.com");
strSubject = strreplace(this.subjectText(),'\r\n','');
item.subject(strSubject); //item.body("testtesttest");
for(i = 1;i<=conlen(this.attachPath());i++)
{
if(winapi::fileExists(conpeek(this.attachPath(),i)))
{
attach.add(@""+conpeek(this.attachPath(),i));
}
else
{
info(strfmt("not exist %1",conpeek(this.attachPath(),i)));
}
}
item.attachments();
//item.send(); //直接发送
item.display(true);//显示outlook界面
}
刚开始做的时候,也很纠结,不知道多个附件该如何附加,后来是通过参考在.net当中outlook添加附件,才慢慢摸索出来的。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂