I have an .xls file containing a large amount of emails, which i want to add to outlook via matlab. Processing the .xls file is no problem.
我有一个包含大量电子邮件的.xls文件,我想通过matlab添加到outlook。处理.xls文件没问题。
I found it is possible to send mails via matlab using h = actxserver('outlook.Application'
and i figured i might be able to use this for my purpose. I'm however completely unfamiliar with the ActiveX/COM interface, and how to use it.
我发现有可能通过matlab使用h = actxserver发送邮件('outlook.Application',我想我可能会将此用于我的目的。但是我对ActiveX / COM接口完全不熟悉,以及如何用它。
I tried to use get(h) but that did not give me any useful information.
我试图使用get(h),但这并没有给我任何有用的信息。
Two questions. Specifically 1) how can i use Matlab to add contacts.
两个问题。具体来说1)我如何使用Matlab添加联系人。
And secondly, more general, how would i be able to find out what i can do with 'h' in this case? I see people using h.Subject
or h.To
How would i be able to find out the possible things (like Subject or To) i can do with h?
其次,更一般的是,在这种情况下,我怎样才能找到我能用'h'做什么?我看到人们使用h.Subject或h.To我怎样才能找到可以用h做的可能的东西(如Subject或To)?
2 个解决方案
#1
1
To add a contact you need to create a ContactItem
object through the ActiveX control:
要添加联系人,您需要通过ActiveX控件创建一个ContactItem对象:
h = actxserver('outlook.Application');
newContact = h.CreateItem('olContactItem');
newContact.FirstName = 'John';
newContact.LastName = 'Smith';
newContact.Email1Address = 'john.smith@email.email';
newContact.Save();
% newContact.Display; % To check your work
h.release; % Close the ActiveX interface
See the ContactItem
properties page for a list of other fields you can modify.
请参阅ContactItem属性页以获取可以修改的其他字段的列表。
For the general question, it just takes some poking around in Outlook's Object Model Reference
对于一般问题,它只需要在Outlook的对象模型参考中进行一些讨论
#2
1
I would still suggest using outlook for sending the emails so you have all the up-to-date functionalities, and MS is constantly updating office 365 and it would not be the first time when an MS interface was screwed up by microsoft update.
我仍然建议使用outlook来发送电子邮件,这样你就拥有了所有最新的功能,并且MS不断更新office 365,这不是第一次MS接口被微软更新搞砸了。
In any case, you are right, there is a active X interface that can be used, before you use it, you have to run matlab using administrator privilege (if you are on windows) and make sure you have a Matlab version > 2010 rb (the version I am testing on).
在任何情况下,你是对的,有一个可以使用的活动X接口,在你使用之前,你必须使用管理员权限运行matlab(如果你在Windows上)并确保你有一个Matlab版本> 2010 rb (我正在测试的版本)。
if you are using h = actxserver('outlook.Application') all this does is create an OLE server with the given application ID, so get() will not grab you anything other than version number and server ID etc. However, it should enable you to call on functions belonging to that server (i.e. the functionality of outlook.Application, so in general, to send an email :
如果您使用的是h = actxserver('outlook.Application'),所有这一切都是创建一个具有给定应用程序ID的OLE服务器,因此get()不会获取除版本号和服务器ID等之外的任何内容。但是,它应该使您能够调用属于该服务器的函数(即outlook.Application的功能,所以一般来说,发送电子邮件:
mail = h.CreateItem('olMail');
mail.Subject = subject;
mail.To = to;
mail.BodyFormat = 'olFormatHTML';
mail.HTMLBody = body;
% Add attachments, if specified.
if nargin == 4
for i = 1:length(attachments)
mail.attachments.Add(attachments{i});
end
end
% Send message and release object.
mail.Send;
h.release;
Note the above code was taken from Mathworks, I did not write them and probably would never try... but it has been tested to work on my local station.
请注意,上面的代码来自Mathworks,我没有编写它们,可能永远不会尝试......但它已经过测试,可以在我的本地站上运行。
To answer your second question, what functions you can call on depends on what functions are available in outlook.Application, this is available from microsoft application dev, which are all the functions you can call from the object.
要回答第二个问题,您可以调用哪些函数取决于outlook.Application中可用的函数,这可以从microsoft application dev获得,它们是您可以从对象调用的所有函数。
Also note, all parameters are passed as STRINGS to the Object through the OLE, so there is no Matlab functionality here and you cannot use any of the Matlab functionality in calls with the Object, if you want to do something clever - you need to pass VB language through as strings to the Object.
另请注意,所有参数都通过OLE作为STRINGS传递给Object,因此这里没有Matlab功能,如果你想做一些聪明的事情,你不能在使用Object的调用中使用任何Matlab功能 - 你需要通过VB语言通过as作为Object的字符串。
#1
1
To add a contact you need to create a ContactItem
object through the ActiveX control:
要添加联系人,您需要通过ActiveX控件创建一个ContactItem对象:
h = actxserver('outlook.Application');
newContact = h.CreateItem('olContactItem');
newContact.FirstName = 'John';
newContact.LastName = 'Smith';
newContact.Email1Address = 'john.smith@email.email';
newContact.Save();
% newContact.Display; % To check your work
h.release; % Close the ActiveX interface
See the ContactItem
properties page for a list of other fields you can modify.
请参阅ContactItem属性页以获取可以修改的其他字段的列表。
For the general question, it just takes some poking around in Outlook's Object Model Reference
对于一般问题,它只需要在Outlook的对象模型参考中进行一些讨论
#2
1
I would still suggest using outlook for sending the emails so you have all the up-to-date functionalities, and MS is constantly updating office 365 and it would not be the first time when an MS interface was screwed up by microsoft update.
我仍然建议使用outlook来发送电子邮件,这样你就拥有了所有最新的功能,并且MS不断更新office 365,这不是第一次MS接口被微软更新搞砸了。
In any case, you are right, there is a active X interface that can be used, before you use it, you have to run matlab using administrator privilege (if you are on windows) and make sure you have a Matlab version > 2010 rb (the version I am testing on).
在任何情况下,你是对的,有一个可以使用的活动X接口,在你使用之前,你必须使用管理员权限运行matlab(如果你在Windows上)并确保你有一个Matlab版本> 2010 rb (我正在测试的版本)。
if you are using h = actxserver('outlook.Application') all this does is create an OLE server with the given application ID, so get() will not grab you anything other than version number and server ID etc. However, it should enable you to call on functions belonging to that server (i.e. the functionality of outlook.Application, so in general, to send an email :
如果您使用的是h = actxserver('outlook.Application'),所有这一切都是创建一个具有给定应用程序ID的OLE服务器,因此get()不会获取除版本号和服务器ID等之外的任何内容。但是,它应该使您能够调用属于该服务器的函数(即outlook.Application的功能,所以一般来说,发送电子邮件:
mail = h.CreateItem('olMail');
mail.Subject = subject;
mail.To = to;
mail.BodyFormat = 'olFormatHTML';
mail.HTMLBody = body;
% Add attachments, if specified.
if nargin == 4
for i = 1:length(attachments)
mail.attachments.Add(attachments{i});
end
end
% Send message and release object.
mail.Send;
h.release;
Note the above code was taken from Mathworks, I did not write them and probably would never try... but it has been tested to work on my local station.
请注意,上面的代码来自Mathworks,我没有编写它们,可能永远不会尝试......但它已经过测试,可以在我的本地站上运行。
To answer your second question, what functions you can call on depends on what functions are available in outlook.Application, this is available from microsoft application dev, which are all the functions you can call from the object.
要回答第二个问题,您可以调用哪些函数取决于outlook.Application中可用的函数,这可以从microsoft application dev获得,它们是您可以从对象调用的所有函数。
Also note, all parameters are passed as STRINGS to the Object through the OLE, so there is no Matlab functionality here and you cannot use any of the Matlab functionality in calls with the Object, if you want to do something clever - you need to pass VB language through as strings to the Object.
另请注意,所有参数都通过OLE作为STRINGS传递给Object,因此这里没有Matlab功能,如果你想做一些聪明的事情,你不能在使用Object的调用中使用任何Matlab功能 - 你需要通过VB语言通过as作为Object的字符串。