VBScript to send outlook email without asking user to log in - outlook

I made VBScript to send Outlook email without prompt user to log in in his or her account. But when I tried to run the script, it prompts me to log in. I don't know is it possible to send it without asking, but any help is nice. Here's my code:
'Create an Outlook object
Dim Outlook
Set Outlook = CreateObject("Outlook.Application")
'Create e new message
Dim Message
Set Message = Outlook.CreateItem(olMailItem)
With Message
.Subject = "subject"
.Body = "body"
'Set destination email address
.Recipients.Add ("test#outlook.com")
'Set sender address If specified.
'Const olOriginator = 0
'If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator
'Send the message
.Send
End With
I'm sorry, the code is so dirty.
PS: I'm not good with English. Please understand if i wrote something wrong.

Use the Logon method only to log on to a specific profile when Outlook is not already running. This is because only one Outlook process can run at a time, and that Outlook process uses only one profile and supports only one MAPI session. When users start Outlook a second time, that instance of Outlook runs within the same Outlook process, does not create a new process, and uses the same profile.
If Outlook is already running, using this method does not create a new Outlook session or change the current profile to a different one.

You can turn profile prompt off in Control Panel | Mail | Show Profiles.

Related

Select mailbox for Microsoft Outlook when using Applescript

I'm using Applescript to automatically draft and send emails in Microsoft Outlook. While everything is working as expected to send emails from my own account, I want to adjust the script to send emails from a different account that I have access to in Outlook. I've found this post, but the approach shown there generates an error for me.
https://macscripter.net/viewtopic.php?pid=185222#p185222
How can I adjust the script below to select the correct mailbox to send my email from? When I use the script below, the following error is generated when I attempt to save it.
Syntax Error
Expected class name but found identified
I've Google this error message, but haven't been able to find anything relevant to my task of changing the account the email is sent from.
set theAccount to the first exchange account whose name is "second.account#company.com"
set recipientAddress to "first.last#company.com"
set theSubject to "This is only a test"
set theContent to "<html><body><p>This is only a test.</p></body></html>"
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {account:theAccount, subject:theSubject, content:theContent}
tell newMessage
make new recipient at newMessage with properties {email address:{address:recipientAddress}}
end tell
save in drafts
end tell

how to send the Outlook Email and overcome standard security notification with VBScript or Batch?

I am trying to automate autosending Outlook emails with VBScript.
I tried following ways:
Sending emails programmatically with Mail.Send command in VBScript
Attempting to send EMails programmatically does not seem to work due to security reasons.
Here is my code sample:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to= "xx.xxx.com"
Mail.Subject = "AUTOMATED UPDATE: is ready to be booked"
Mail.HTMLBody = "please see attachments... :)"
Mail.Display
Mail.send
ol.quit
Set Mail = Nothing
Set ol = Nothing
POP-UP BLOCK I GET:
Sending Mails with SendKeys Method (working but unstable method)
Here is my code sample:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "outlook"
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to= "xxxx.com"
Mail.Subject = "AUTOMATED UPDATE: "&file_name&" is ready to be booked"
Mail.HTMLBody = "please see attachments... :)"
Mail.Attachments.add "xxxx"
Mail.Display
WshShell.AppActivate(Mail.Subject&" - Message (HTML)")
WshShell.SendKeys "%{s}",1
WScript.Sleep 40000
ol.quit
Set Mail = Nothing
Set ol = Nothing
WshShell.Run "taskkill /im outlook.exe", , True
This method works, but supposes that no one should interrupt the process and klick something. It is very unstable and that's why I am looking for other opportunities.
Having googled till 999999 page :) of Google Search, I found the following options, but neither of them is workable in my case:
Use Redemption - acc. to company policy I am not allowed to use third party application
Use ClickYes - acc. to company policy I am not allowed to use third party application
Send Emails through CDO - I cannot connect to SMTP Server because does not know the password therefrom and not authorized to get it
I also looked if it is possible to send keys on the background window - unfortunately it is NOT possible.
Going to TrustCenter of Outlook and change setting - it is not allowed to do that acc. to company policy
Can anyone advise some other workaround?
The prompt will not be shown if an up-to-date antivirus app is installed.
You get the security prompts because Outlook is configured on the client computer in one of the following ways:
Uses the default Outlook security settings (that is, no Group Policy set up)
Uses security settings defined by Group Policy but does not have programmatic access policy applied
Uses security settings defined by Group Policy which is set to warn when the antivirus software is inactive or out of date
You can create a group policy to prevent security prompts from displaying if any up-to-date antivirus software is installed on the system or just turn these warning off (which is not really recommended).
Read more about that in the Security Behavior of the Outlook Object Model article.

How to automate windows 10 email client from vb6 application

Our vb6 application allows users to open an email with an attachment in Outlook (user clicking on cmdEmail opens Outlook in new process with details populated and a document attached). I've been asked to extend this so that an email with attachment can be opened in the new Windows 10 mail app.
Is anyone aware of any way to do this?
I've tried a few avenues:
I can't use mailto: because of the attachment requirement. I can create the email in the win10 app, but Attachment= or Attach= don't work
I've tried Simple MAPI and CDO but had trouble even getting it to work with Outlook because of an "unspecified error" when trying to send with showdialog = true, or a security warning when opening the address book when showdialog = false (although showing the client is a requirement). I've also read it's not supported by Outlook 2010 (or 2007 for CDO) so I'm doubtful it will be supported by the mail app.
The vb6 application automates Outlook by creating an Outlook.Application object (same sort of method as shown here https://support.microsoft.com/en-us/kb/220595). Is there anyway to recreate this sort of logic with the Mail app? I can't see any object models online or see an object library in my program files.
Has anyone else managed to do this, or might be able to suggest an avenue I can explore? I've not done anything like this before (even mailto was new to me) so any suggestion or point-in-a-direction would be appreciated
Thanks

Greasemonkey to prompt outlook

I have a new Script I'm building for my office where a greasemonkey button, aside from prompting to enter an specific error number also needs to open outlook and send a message to a certain address with said error number in the subject line...
Any ideas I'm tapped out
Code:
addButton(f_l, 'Error number', function() {
url = prompt("Please provide the full error number","");
surround('','');
});
It enters the text into the box on the page, but it doesn't create a new email.
The How to automate Outlook from another program article describes all the required steps for automating Outlook from another applications.
Also see How To: Create and send an Outlook message programmatically.

Use applescript to set multiple signatures in Outlook 11

I'm trying to create an applescript to use on outgoing email messages in Outlook 11 for Mac to dynamically set the email signature in the message based on who the sender address is. I have multiple accounts in Outlook, and would like to change the signature based on which one I'm using. Below is the code I've been trying, but have not had any success. Any advice?
tell application "Microsoft Outlook"
if message sender contains {name:"emailaddress"} then
set the message signature to signature {name:"signaturename"}
else
set the message signature to signature {name:"signaturename2"}
end if
end tell
If I understand your question, I think Outlook 2011 has this capability built in, without the need for any scripting.
Click "Outlook", then "Preferences..." from the Outlook menu
Click the "Signatures" icon
Set up the signatures you need if you haven't already done so, and give them meaningful names
Click the "Default Signatures..." button
Associate the relevant signature to each account that you require
There seems to be a bit of a trick to using this. If you want the signature for account X to appear automatically in a new message, then you must first select a folder from account X before creating a new message. If you do that, then the message should include the correct signature that you have set up for that account.

Resources