Send email with FROM field in Matlab - matlab

I am trying to add the field FROM in my matlab function to send an email with outlook.
This function works (without the from):
function sendolmail(to,subject,body,attachments, from)
%Sends email using MS Outlook. The format of the function is
%Similar to the SENDMAIL command.
% Create object and set parameters.
h = actxserver('outlook.Application');
mail = h.CreateItem('olMail');
mail.Subject = subject;
mail.To = to;
mail.BodyFormat = 'olFormatHTML';
mail.HTMLBody = body;
% THIS PART DOES NOT WORK
if nargin ==5
mail.From = from;
end
% 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;
However, when I add from then I get the error:
No public property From exists for class
Interface.00063034_0000_0000_C000_000000000046.

As already stated, there is no From attribute in MailItem objects. There are many attributes referring to the sender: Sender, SenderEmailAddress, SenderEmailType, SenderName... but all of them, except Sender, are read-only. This means they cannot be set, and you must rely uniquely on the Sender property, which accept object instances of type AddressEntry.
I'm not sure that this will work, because such mechanic would be easily abused by malicious users... but you can try the following:
if (nargin == 5)
recipient = h.Session.CreateRecipient(from);
mail.Sender = recipient.AddressEntry;
end

Here are all the properties of the MailItem class, which is what you are creating through this interface: https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.mailitem_members.aspx
It looks like you need to set either Sender or SendUsingAccount. However, since neither of these take strings, you'll have to retrieve an object of the appropriate type using the matlab interface. It seems to me that you should be able to use
mail.SendUsingAccount= h.Session.Accounts.Item(3); %Select the third account
to set this property; however, it seems like there may be some issues with that, according to this source. Unfortunately, I don't have outlook setup, some I'm not able to try it myself.

Related

VB Script to change the from field of emails in Outbox

I have emails in my Outbox in Outlook and I'd like to run a vb script to change the from field of these emails to some other email
I managed to do the following but it doesn't work as I'd like to and therefore I am missing the main piece. I'd appreciate if someone could help.
intFolderOutbox = 4
msoFileDialogOpen = 1
' Load requied objects
Set WshShell = WScript.CreateObject("WScript.Shell") ' Windows Shell
Set ObjOlApp = CreateObject("Outlook.Application") ' Outlook
Set ns = ObjOlApp.GetNamespace("MAPI") ' Outlook
Set box = ns.GetDefaultFolder(intFolderOutbox) ' Outlook
For Each Item In box.Items
*** HERE IS WHAT I NEED TO REPLACE THE FROM FIELD ****
Item.sender = "email2#gmail.com"
Item.Update
Item.Save
Next
Something like the following works adding a recipient but I couldn't find the equivalent to the from field.
Item.Recipients.Add "email2#gmail.com"
Here is something that could help but it doesn't work in my case
Set oAddrEntry = CreateObject("MAPI.AddressEntry")
oAddrEntry.Name = SYSTEM_ADDRESS
oAddrEntry.resolve
Set oNewMsg.sender = oAddrEntry
oNewMsg.Update
oNewMsg.Send
Thanks
Firstly, once a message is submitted (and moved to Outbox) it cannot be touched - it belongs to the spooler.
Secondly, you cannot send on behalf of an arbitrary user. In case of Exchange, set the MailItem.SentOnBehalfOfName property to the name of the Exchange mailbox on whose behalf the current user can send. In case of POP3/SMTP accounts, set the MailItem.SendUsingAccount property to one of the accounts from the Namespace.Accounts collection.

Passing arguments to Access Forms created with 'New'

I have a form called 'detail' which shows a detailed view of a selected record. The record is selected from a different form called 'search'. Because I want to be able to open multiple instances of 'detail', each showing details of a different record, I used the following code:
Public detailCollection As New Collection
Function openDetail(patID As Integer, pName As String)
'Purpose: Open an independent instance of form
Dim frm As Form
Debug.Print "ID: " & patID
'Open a new instance, show it, and set a caption.
Set frm = New Form_detail
frm.Visible = True
frm.Caption = pName
detailCollection.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
End Function
PatID is the Primary Key of the record I wish to show in this new instance of 'detail.' The debug print line prints out the correct PatID, so i have it available. How do I pass it to this new instance of the form?
I tried to set the OpenArgs of the new form, but I get an error stating that OpenArgs is read only. After researching, OpenArgs can only be set by DoCmd (which won't work, because then I don't get independent instances of the form). I can find no documentation on the allowable parameters when creating a Form object. Apparently, Microsoft doesn't consider a Constructor to be a Method, at least according to the docs. How should I handle this? (plz don't tell me to set it to an invisible text box or something) Thanks guys, you guys are the best on the net at answering these questions for me. I love you all!
Source Code for the multi-instance form taken from: http://allenbrowne.com/ser-35.html
Inside your Form_detail, create a custom property.
Private mItemId As Long
Property Let ItemID(value as Long)
mItemId = value
' some code to re query Me
End Property
Property Get ItemId() As Long
ItemId = mItemId
End Property
Then, in the code that creates the form, you can do this.
Set frm = New Form_detail
frm.ItemId = patId
frm.Visible = True
frm.Caption = pName
This will allow you to pass an ID to the new form instance, and ensure it gets requeried before making it visible. No need to load all of the results every time if you're always opening the form by Newing it. You let the property load the data instead of the traditional Form_Load event.
This works because Access Form modules are nothing more than glorified classes. Hope this helps.
You could try applying a filter:
frm.Filter = "[ID] = " & patID
frm.FilterOn = True
The Record Source of the Detail form will need to be set to the table to which the ID belongs.
UPDATE
As you requested, here is the code to set the RecordSource:
frm.RecordSource = "select * from TableName where [ID] = " & patID
This is probably cleaner than using a filter given that a user can remove the filter (depending on the type of form).

Excel VBA: using R1C1 format, "Application defined or object defined error"

I am trying to create a formula that references other cells, but I keep getting this "Application defined or object defined error". I use R1C1 convention instead of Offset.
My Code:
Note: This code could be anywhere, I just need it to work. Also, I don't use the code like this. It is used in a reporting tool, but this is just similar code (to what I actually use) sufficient enough to show my problem
Cells(1, 1).Value = "5/1/2014 6:30"
soiDate = "$A$1"
Cells(10, 6).Value = "6/5/2014 14:12"
Cells(10, 10).Formula = "=(R[0]C[-4]-" & soiDate & ")*24" 'Error Occurs Here
UPDATE:
The following does not work either:
Cells(10, 10).FormulaR1C1 = "=(R[0]C[-4]-" & soiDate & ")*24"
Try this:
Cells(10, 10).FormulaR1C1 = _
"=(R[0]C[-4]-" & Range(soiDate).Address(, , xlR1C1) & ")*24"
It errors out since you kinda mixed up R1C1 reference to A1.
Just be consistent, you can use Range Object address property to convert reference. HTH.

How to add user specified items to OPC data group

I am creating a MATLAB application which connects to an OPC Server and reads the Tag properties. The MATLAB documentation is telling me that I can add a group, add tag items, and then read the value:
grp = addgroup(da, 'ExRead');
itm = additem(grp, 'Tag.Argument');
The problem is that I don't know the tag argument, in my app the user is selecting an available tag in a popupmenu and the value is written to a string, but when I call:
val = get(handles.popupmenu1, 'Value'); // Ask for Value selected item
string_val = get(handles.popupmenu1, 'String'); // Ask for string
stringName = string_val{val}; // Ask for string corresponding to the specified value
set(handles.text1, 'String', stringName); // Display the selected tag
item1 = additem(Group1, stringName); // Add the selected string to a global group "Group1"
read1 = read(Group1, item1); // Read the value
set(handles.text11, 'String', read1); // Display the value
But when I run the code MATLAB generates errors. I guess the problem is item1 = additem(Group1, stringName); In all the MATLAB documentation examples I see something like item1 = additem(Group1, 'adres.adres.1'); This should explain why I am unable to add any data to the Group1.
But how can I add an item to a taggroup which must be specified/selected by a user?
Group1 appears to be a variable here, that is undefined. Perhaps you meant to type 'Group1', with quotes? That would add item to a group called Group1.
If I get it right, you don't know which tag names you should use.
The correct ItemID (Tag name) is typically found by browsing the server address space.
Before you implement browsing in your application (if possible with MATLAB), you can use test clients, such as Prosys OPC Client to browse the address space and find the proper ItemID(s) to use.

Extjs Form Action Submit - Custom override?

Looking at the source code of Action.Submit, I'm trying to figure out where ext is appending the form's fields to the parameters.
Instead of sending each field as a separate parameter, I want to send something like:
formObj:{field1:value, field2:value}
Currently, each of those values are simply added to the parameter list along with any custom/baseParams.
Where are these formfields being added so that I can change this behaviour?
Thanks.
I'm not sure what your override needs to look like, but you'll probably want to look at Ext.Ajax.request() (in Core / Connection.js). When posting a form, the fields get serialized there, in this code block:
if(form = Ext.getDom(o.form)){
url = url || form.action;
serForm = Ext.lib.Ajax.serializeForm(form);
p = p ? (p + '&' + serForm) : serForm;
}
If you really want to track the process of creating parameter list, you can refer to Ext.form.Action.getParams.
You should also consider Ext.form.BasicForm.getValues as it returns exactly the result you want, the only problem is that you'll need to send it manually, e.g. using Ext.Ajax.request.