How do I flag email for recipients with Outlook APIs in MATLAB? - matlab

I want to send an email via the Outlook API in MATLAB and I also want to create a task in the recipients' Outlook.
I have tried taking a look at the Outlook API documentation, but all I could find was a reference to 'FlagStatus', which is not a parameter available for 'olMail'.
% Connect to Outlook
outlook = actxserver( 'outlook.Application' );
% Create email
email = outlook.CreateItem( 'olMail' );
% Add email properties
email.To = address;
email.Subject = subject;
email.Importance = 'olImportanceHigh';
email.BodyFormat = 'olFormatHTML';
email.HTMLBody = body;
% Add task properties
email.TaskSubject = taskName;
email.TaskStartDate = datestr( today, 'dd/mm/yyyy' );
email.TaskDueDate = datestr( today + 12, 'dd/mm/yyyy' );
% Set reminder
email.ReminderSet = true;
email.ReminderTime = datestr( today + 7 + 9/24, 'dd/mm/yyyy hh:MM' );
% Send email
email.Send;
The expected behavior would be the same as selecting the option as below:

I believe this is related to the FlagRequest property. To see what it does, run email.Display() after executing your code - you should notice an Outlook "new message" window open. This is what you would see initially,
Then, if you execute:
% Flag for recipient
email.FlagRequest = "<NAME OF FLAG HERE>";
You'd get:
... which is the same message that would appear when setting this flag manually through the Outlook GUI. Two caveats:
If you open the flag menu after running the command, it would show that a local flag would be created, instead of a remote one. This looks like an outlook bug.
The remote flag time/date is what you put in ReminderTime. I think it would be better to set FlagRequest before ReminderSet and ReminderTime for it to be reflected correctly in the GUI (when using email.Display).

Related

BizTalk Orch/SMTP - Microsoft.XLANGs.BaseType.Content must be a message property of

This is related to my question from 2017: How Set Attachment Name to Show Properly in Outlook
This time, I have an orchestration with the following in a construct shape:
attachmentName = System.IO.Path.GetFileName(
msg_Ledger6002_File_XmlDoc
(FILE.ReceivedFileName));
msg_Email.BodyPart = new ABC.Ledger6002.Component.RawString("See attached email.");
msg_Email.AttachmentPart = msg_Ledger6002_File_XmlDoc;
// attachmentName is set earlier in orch so we could write it to EventLog for debugging
msg_Email.AttachmentPart(MIME.FileName) = attachmentName;
//msg_Email.AttachmentPart(MIME.ContentDescription) = "body";
//msg_Email.AttachmentPart(MIME.ContentTransferEncoding) = "base64";
// These are working
msg_Email(SMTP.Subject) = "Ledger6002 File";
msg_Email(SMTP.SMTPTo) = msg_Config_Email.smtpToEmail;
msg_Email(SMTP.From) = msg_Config_Email.smtpFromEmail;
msg_Email(SMTP.SMTPAuthenticate) = 0; // do not authenticate to SMTP server
// trying these two new parms below
msg_Email(SMTP.EmailBodyTextCharset) = "UTF-8";
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
The last line above gives me an expression shape not valid, and when I mouse over it it says identifies the error as:
Microsoft.XLANGs.BaseType.Content must be a message property of
msg_email.
Before I added the two lines under the comment "trying these two new parms below", I am getting an email with the desired attachment. The problem is that it is just called "body" and when I do "save as" from Outlook, it wants to call it "body" instead of the name of the file I dropped.
I'm using a "specify later" statically configured SendPort with PassThru for the Pipeline. I have tried a pipeline with MimeEncoder, but that caused the attachment to appear in the body. I would like to move to a dynamic pipeline, but so far I've got the static one working except for the name assigned to the file attachment.
To fix the error: "Microsoft.XLANGs.BaseType.Content must be a message property of msg_email.", I just needed to include the part name (the message is associated with a multipart message type, and I didn't include the partname):
Wrong:
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
Right:
msg_Email.BodyPart (Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
I'm still working on getting the email with attachment to come out correctly, but so far this post https://social.msdn.microsoft.com/Forums/en-US/988b0d91-1e5a-4f73-b30d-417d6ea9fa75/attachment-name-in-outlook-is-ok-see-on-exchange-always-named-body?forum=biztalkgeneral seems to be the best explanation.

Redemption in MS Access / Outlook (trying to include a separate message file in email)

This code is in MS Access (2010) VBA, using the Redemption library with Microsoft Outlook 2010.
I had this process working before, but we recently had a Citrix upgrade that I guess reset something in my Outlook and now the process no longer works.
I have a folder of .msg files which are basically pre-made email templates with all the proper formatting, images, text, etc.
This is what I was doing before:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
Now when the email is sent, the .msg contents aren't present at all -- the only thing that shows up is the "extra message" that I prepended to the HTMLBody.
What do I need to change or update? Is this something I need to change in the code, or in my Outlook settings, etc?
Extra: body insertion:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
You cannot concatenate 2 HTML strings and expect a valid HTML string back - the two must be merged - find the position of the "<body"substring in the original HTML body, then find the positon of the following ">" (this way you take care of the body element with attributes), then insert your HTML string following that ">".

Access 2007 to Word, Outlook for 2-step Mail Merge

My VBA does the email merge wonderfully ... except, I have to click on "allow" - from Outlook - twice, for each email generated. Is there a way to programatically get around this?
I am running Windows 7 Enterprise, SP1. MS Office 2007. Computer is tightly locked down. HTML format e-mail not supported - only plain text. I do not have local admin rights. I am not able to install additional add-ins or third party software, as I've found suggested numerous times.
Here is my working VBA:
Private Sub Send_Email_Merge()
Dim sDBPath As String
'Word variables
Dim oWD As Word.Application
Dim oDoc As Word.Document
Dim RecCount As Long
'Sanity check on how many e-mails to be sent
RecCount = DLookup("[Email Count]", "qry_EmailMerge_Count")
Debug.Print RecCount
Set oWD = CreateObject("Word.Application")
oWD.Visible = True
Set oDoc = oWD.Documents.Open("C:\MyTemp\MyDocs\MyEmailMerge.docx")
With oDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = "C:\MyTemp\MydBs\My_Engine.accdb"
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [qry_E Mail Merge]"
End With
oWD.Activate
oWD.Documents.Parent.Visible = True
oWD.Application.WindowState = 1
oWD.ActiveWindow.WindowState = 1
With oDoc.MailMerge
.Destination = wdSendToEmail
.MailAddressFieldName = "Email Address"
.MailSubject = "Your Action Required"
.MailFormat = wdMailFormatPlainText
.Execute
End With
oWD.Activate
oWD.Documents.Parent.Visible = True
oWD.Application.WindowState = 1
oWD.ActiveWindow.WindowState = 1
oWD.ActiveDocument.Close
oWD.Quit
Set oWD = Nothing
Set oDoc = Nothing
End Sub
Any help is appreciated.
You can automate directly from Access. See How to automate Outlook from another program for more information. It describes all the required steps for automating Outlook from another applications.

PHPMailer AltBody is not working

PHPMailer Version 5.2.7
$mailerObject = new PHPMailer;
$mailerObject->CharSet = 'UTF-8';
$mailerObject->IsSMTP();
$mailerObject->Host = 'dsfdf.sdfsdf.com';
$mailerObject->SMTPAuth = TRUE;
$mailerObject->Username = 'dfgdfg';
$mailerObject->Password = 'dfgdfgdfg';
$mailerObject->SMTPSecure = 'tls';
$mailerObject->WordWrap = 60;
$mailerObject->From = 'alex#test.de';
$mailerObject->FromName = 'test.de';
$mailerObject->AltBody = $bodyTextTemp;
$mailerObject->MsgHTML($bodyHtmlTemp);
I am sending an HTML-Mail and an Text-Mail. In Thunderbird in HTML-Mode HTML is correctly shown. In Text-Mode you cant see the Text-Content ($bodyTextTemp), but the HTML-Content ($bodyHtmlTemp) where all HTML-Tags were removed (looks very ugly...).
Looking to the Mail-source, I can see that the AltBody wasnt send.
Why PHPMail dont accept my AltBody?
Because msgHTML overwrites AltBody. If you want to set Body and AltBody yourself, just set them. msgHTML is a convenience function to do several things for you, but you don't need to use it. If you want to use it but also set AltBody, just set it after you call msgHTML.

How to mail a screen captured image using corona SDK

I am new to corona SDK, but I've managed to capture my app scene using the following code:
local function captureArea()
local myCaptureImage = display.captureBounds(display.currentStage.contentBounds, true)
myCaptureImage:removeSelf()
myCaptureImage = nil
end
bg:addEventListener("tap",captureArea)
This works perfectly.
Now I need to send the captured image(with a specific name, say: screen_1.png) to my friend via email. I've used Composing E-mail and SMS for refference, but I fail to understand how I can add this saved image in the attachment field of mail options.
Please give me a proper solution that how can I attach and send the above saved image via email.
display.captureBounds is good for saving the whole screen to the directory. But it usually saves the file with increase in last index. So it may be difficult to read them correctly. So I prefer display.save. But it is not a straight way.
For doing this, you have to:
First create a localgroup.
Then add the screen objects to that group.
Return the display group
Use display.save to save the entire group displayed.
Create mail option and add attachment image from baseDirectory
Call mail Popup
I am giving a sample here:
-- creating the display group --
local localGroup = display.newGroup()
-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,_w,_h)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)
local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)
-- Then do as follows --
local function takePhoto_andSendMail()
-- take screen shot to baseDirectory --
local baseDir = system.DocumentsDirectory
display.save( localGroup, "myScreenshot.jpg", baseDir )
-- Create mail options --
local options =
{
to = { "krishnarajsalim#gmail.com",},
subject = "My Level",
body = "Add this...",
attachment =
{
{ baseDir=system.DocumentsDirectory, filename="myScreenshot.jpg", type="image" },
},
}
-- Send mail --
native.showPopup("mail", options)
end
rect:addEventListener("tap",takePhoto_andSendMail)
This will do it...
Keep coding........ :)