Counting Mails in Outlook with Autohotkey - outlook

I tried to write a script, that counts the e-Mails in a specific public exchange folder in outlook.
If there are Mails in subfolder2, a Messagebox should open and tell me, how many Mails there are. I tried this, but it did not work.
Outlook := ComObjActive("Outlook.Application")
mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")
if (mail.Items.Count>0)
{
msgbox % mail.Items.Count "Mails in folder"
}
else
{
msgbox No Mails.
}
Does anyone has a idea, how I should change the script, that it works?

Please try to use this:
mail := Outlook.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")

You must retrieve subfoldersone at a time, you cannot specify a path. Change the line
mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")
to
mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2")

I got it.
I simply removed the Variable.
Outlook := ComObjActive("Outlook.Application")
if (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count>0)
{
msgbox % Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count "Mails in folder"
}
else
{
msgbox No Mails.
}
Thanks for the help :D

Related

Outlook unable to handle bracket > in e-mail correctly

I have an external system feeding draft e-mail in outlook.
The e-mail address is in format:
Username <abcd#gmail.com; efgh#gmail.com>
When I preview e-mail in outbox, the outlook wrongly treated the e-mail as "Username <abcd#gmail.com" and "efgh#gmail.com>"
But, if I type the above wordings manually, Outlook 2016 check name feature can correctly recognize:
Username abcd#gmail.com; efgh#gmail.com
Any thoughts why Outlook cannot check names properly for system generated e-mail? The external system correctly transfer the string to Outlook "Username <abcd#gmail.com; efgh#gmail.com>"
Use the Recipient.Resolve method which attempts to resolve a Recipient object against the Address Book.
Sub AssignTask()
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
Set MyItem = Application.CreateItem(olTaskItem)
MyItem.Assign
Set myDelegate = MyItem.Recipients.Add("Eugene Astafiev")
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = Now + 30
myItem.Display
myItem.Send
End If
End Sub
You may also find the How To: Fill TO,CC and BCC fields in Outlook programmatically article helpful.
Username <abcd#gmail.com; efgh#gmail.com> format is incorrect. It must be Username <abcd#gmail.com>; Username <efgh#gmail.com>

Fetch an Unread email from a particular address in outlook with VB Script

I want to get the email address of the unread mail which is from a particular sender.i tried the following code but it did'nt work
Set olApp=CreateObject("Outlook.Application")
Set olMAPI=olApp.GetNameSpace("MAPI")
Set oFolder = olMAPI.GetDefaultFolder(6)
Set allEmails = oFolder.Items
For Each email In oFolder.Items
If email.Unread = True Then
If email.SenderEmailAddress="Kalyanam.Raghuram#xxxx.com" Then
MsgBox email.Subject
End If
End If
Next
so i checked what actually 'email.SenderEmailAddress' is verifying with then by inserting this code
For Each email In oFolder.Items
If email.Unread = True Then
MsgBox email.Subject
MsgBox email.SenderEmailAddress
End If
Next
it gave me some output which cannot be understood but readable.Please let me know any solution for it.
Dio you mean you got back an EX type address instead of the expected SMTP?
Have you looked at the _ExchangeUser.PrimarySmtpAddress?
In your case you can use MailItem.Sender.GetExchangeUser.PrimarySmtpAddress. Be prepared to handle nulls as each value can be null.
The code you posted worked for me, I am on Windows Vista with Outlook 2007
One thing I would change is this
If LCase(email.SenderEmailAddress) = LCase("Kalyanam.Raghuram#xxxx.com") Then
wscript.echo email.Subject
End If

How send mail with vbscript?

i need to send a file attached to an email that must be setn to specific user through smtp server with auth. How can i do that in vbscript?
Thanks.
You can just take a look here:
how to send an email with attachment in vb.net?
Try the following:
Dim oMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
oMsg.From = "noone#nobody.com"
oMsg.To = "someone#somewhere.com"
oMsg.Subject = "Email with Attachment Demo"
oMsg.Body = "This is the main body of the email"
Dim oAttch As MailAttachment = New MailAttachment("C:\myattachment.zip")
oMsg.Attachments.Add(oAttch)
SmtpMail.Send(oMsg)
I have no experience with vbscript of VB for that matter... But a quick Google gave me this result - it looks simple enough.
I hope this helps :)

Windows programming - send email script

Looking for a simple script that would run on windows 2003 server that would basically send me an email. What I plan to do us the windows services auto recovery manager to trigger the script.
I did find a reference to how I can trigger the use of this script: How to monitor Windows services
But I need some help on writing an send email script that would work for windows platform. I'm not sure what language would be best for this. thanks.
One simple way would be to use javascript (or VBscript). If you google for "Server.CreateObject("CDO.Message")" you will find more examples.
Put the code below in a file with extension: ".js", for example email.js
To call use "cscript email.js" on the command line. Replace server name and emails with valid values.
Windows 2003 should have CDO installed. The script used to work on windows XP and server 2003. This example uses smtp server over the network but there are other options too.
Powershell is probably available for server 2003 .. so it could be another option.
============================== code ==============================
function sendMail ( strFrom, strTo, strSubject, strMessage ) {
try {
objMail = Server.CreateObject("CDO.Message");
objConfig = Server.CreateObject("CDO.Configuration");
objFields = objConfig.Fields;
with (objFields) {
Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2;
Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "xxxxsmtp.xxxserver.xxorg";
Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25;
Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30;
Update();
}
with (objMail) {
Configuration = objConfig;
To = strTo; //"\"User\" ,"\"AnotherUser\" ;"
From = strFrom;
Subject = strSubject;
TextBody = strMessage;
//if we need to send an attachement
//AddAttachment("D:\\test.doc");
Send();
}
}
catch(e) {
WScript.Echo(e.message);
return false;
}
delete objFields;
delete objConfig;
delete objMail;
return true;
}
//WScript.Echo('qqq');
sendMail( 'from#xxxxxx.com', 'to#yyy.com' , 'test', 'msg');

Get EntryID of new mail

We made a script that automatically opens the Microsoft Outlook new mail window. Some things have to be filled in already. This works so far:
Set Arguments = WScript.Arguments
If Arguments.Count > 4 Then
Set Outlook = CreateObject("Outlook.Application")
Set BodyObject = CreateObject("Scripting.FileSystemObject")
Set Mail = Outlook.CreateItem(0)
Mail.To = Arguments(0)
Mail.CC = Arguments(1)
Mail.BCC = Arguments(2)
Mail.Subject = Arguments(3)
Set BodyFile = BodyObject.OpenTextFile(Arguments(4))
Mail.Body = BodyFile.ReadAll
BodyFile.Close
For Counter = 5 to (Arguments.Count - 1)
Mail.Attachments.Add Arguments(Counter)
Next
Mail.Display
End If
But know we want to know if that mail gets sent by the user and we also want to know the EntryID of that mail, so we can look it up later.
Now Mail.Display doesn't return anything and the program just ends. It does not wait until the window gets closed. So after Mail.Display, there should be something like: Mail.Wait, or a Mail send event so we can get the EntryID.
Could someone help us out?
Thanks in advance,
Gillis and Emiel
I just found a probable solution from here:
You need to wait and get the EntryID
value after the item has been
delivered from the Outbox. To do this,
subscribe to the Folder.Items.ItemAdd
event on the Sent Items folder. That
event passes the newly added -- i.e.
newly sent -- item as its argument.
The item must exist first in Outlook to have an EntryID value, use the Save Property and fetch its EntryID right after
Mail.Save
strEntryID = Mail.EntryID
I've got a sample written in VBA for saving notes from Access form to Outlook
Dim outobj As Outlook.Application
Dim outappt As Outlook.NoteItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olNoteItem)
With outappt
If Not IsNull(Me!strBody) Then .Body = Me!strBody
.Save
Me!strEID = .EntryID
End With

Resources