Remove Confirmation Box vbs script - email

I have the following code where i could send mail through my configured outlook.
I can run this vbs using a rule in my outlook which in turn send a mail to the email specified in the script
But i am getting a confirmation box asking a virus or not while running this script to send a mail.
How to get rid of this confirmation box to make always allow to send mails.
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "John.Smith#place.com" ' change this...
MessageSubject = "My Subject"
MessageBody = "DATA"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Send
End If
Set ol = Nothing

I believe your being hit by the now built-in security feature(s) that Microsoft put in place a couple years back with a security patch. The only way I know around it to is to digitally sign the code and then import the certicate that was used to sign that code into the certificate store, or better yet use the Redemption DLL. From the Redemption DLL site:
Outlook Redemption works around
limitations imposed by the Outlook
Security Patch and Service Pack 2 of
MS Office 98/2000 and Office
2002/2003/2007 (which include Security
Patch) plus provides a number of
objects and functions to work with
properties and functionality not
exposed through the Outlook object
model.
The DLL can be downloaded from here: http://www.dimastr.com/redemption/download.htm, and if you look around you can find several examples of how to use it. Here is one to get you started: http://www.utteraccess.com/forums/printthread.php?Cat=&Board=80&main=409393&type=thread
Also please note the peviously posted and answered questions:
How to avoid Outlook security alert when reading outlook message from C# program
Outlook nagging dialog about macro

Related

Add senders Outlook signature to email created with macro from excel

I have set a macro in excel to create email need to have the Outlook signature line for the sender.
Tried
.htmlbody= sig
Signature = .htmlbody
Dim Email_Subject, Email_Send_To, _
Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = Range("B7").Value
Email_Send_To = Range("B9").Value
Email_Body = Range("B8").Value
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.Body = Email_Body
.Display
End With
I want to have the person that is sending the email default signature from outlook show at bottom of email.
Be aware, the Body property of the MailItem class represents the message body in plain text. If you want to preserve any formatting you need to use the HTMLBody property.
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.Body = Email_Body
.Display
End With
The signatures are being kept as separate files in the Signatures folder. You can find this folder in the following location:
Windows XP
C:\Documents and Settings\%username%\Application Data\Microsoft\Signatures
Windows Vista, Windows 7, Windows 8 and Windows 10
C:\Users\%username%\AppData\Roaming\Microsoft\Signatures
To see this folder you must have View hidden files and folders enabled or you can simply copy and paste the above paths in the address bar in Explorer to directly open the folder.
There are three main ways for working with bodies in Outlook:
Body.
HTMLBody.
Word editor. The Inspector class provides the WordEditor property which returns an instance of the Document class from the Word object model which represents the message body. Outlook uses Word as an email editor.
You can read more about that in the Chapter 17: Working with Item Bodies.
I want to have the person that is sending the email default signature from outlook show at bottom of email.
Basically, you just need to insert the signature before the closing <body> tag and set the HTMLBody property to the result HTML markup.

How to set from email address when sending email by automation with outlook

In a legacy vb6 program I am sending email using the full version of outlook (not outlook express) using the code below. Works great.
Now the user wants the 'from:' address to be different for different uses so that when the email is replied to the response will show up in that users inbox in outlook. Currently the email from is the main business email address.
I thought that was an easy fix; I just need to set the .from property in the OutMail object, however it seems there is no '.from' property in the OutMail object. (It may be called something else?)
So at this point I'm wondering how it works now, with no .from specified, and I assume the user has multiple email accounts setup in outlook, it is using the main email for the business, not individual users.
How can I specify a from email address using this technique?
Dim mOutlookApp As Object
Set mOutlookApp = GetObject("", "Outlook.application")
Dim olNs As Object
Set olNs = mOutlookApp.GetNamespace("MAPI")
olNs.Logon
Dim OutMail As Object
Set OutMail = mOutlookApp.CreateItem(0)
'Set the To and Subject lines. Send the message.
With OutMail
.To = txtTo
.CC = txtCC
.Subject = txtSubjext
.HTMLBody = txtBody & vbCrLf
Dim myAttachments As Object
Set myAttachments = .Attachments
vAttach = Split(mAttachments, ",")
For i = 0 To UBound(vAttach)
myAttachments.add vAttach(i)
Next i
Dim myFolder As Object
Set myFolder = olNs.GetDefaultFolder(5) 'olFolderSent
Set .SaveSentMessageFolder = myFolder
StatusBar1.Panels(1).Text = "Status: Sending"
.send
End With
If all you care about is that the reply goes to the right mailbox, set that email address as the reply address. You can do that using Mailtem.ReplyRecipients.Add.

How to activate a Word file inserted programmatically into an Outlook email body?

I have a .Net desktop program that uses Interop to send emails via Outlook. When sending to multiple recipients it uses an email per recipient as the salutation is substituted for personalization. The body of the emails is inserted from a Word file as follows (shortened for clarity):
objOutlook = New Outlook.Application
objItem = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
Dim inspector As Outlook.Inspector = objItem.GetInspector
Dim wordDoc As Word.Document = inspector.WordEditor
wordDoc.Activate() 'Not sure what this does but seems to be needed !
'Insert file contents into body of email.
Dim currentRange As Word.Range = wordDoc.Application.Selection.Range
currentRange.InsertFile(fileName,,,, False)
If at this point I now do an ObjItem.Display, followed by ObjItem.Send then it works perfectly. The Word file contents are put into the email body and the email sent.
But if I simply do an ObjItem.Send (without the .Display) then the email is sent with a blank body.
How do I force the email body to be set with the Word content without having to show the email ?
Try to call the Save method of the MailItem class.
Also you may try to save the document to a file in the HTML format and then set the HTMLBody property of the MailItem class.

using powershell to send emails with different From addresses

I use powershell to send emails from Outlook (complete automatic process). This work perfectly for the default mailbox. I have a lot of restrictions in the development network and can't use any software other than Outlook and powershell.
My question is: Is there a method to send email from a different account in outlook, using powershell
(in my Outlook I have three accounts A, B and C), even if i have one of the as predetermined.
The code that I use is this.
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
$mail.importance = 2
$mail.subject = "SUBJECT"
$mail.body = "BODY"
$mail.To = "email001#xx.com;"
$mail.Send()
Is there a property I can set to make the email origin to be B or C, and not the predetermined A.
You need to set the SendUsingAccount property of the MailItem class which allows to set an Account object that represents the account under which the MailItem is to be sent. For example:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone#example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
Be aware, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

VBScript to modify email content type

I have incoming email set up for SharePoint 2010, and am sending forms from InfoPath using that method, with SMTP server set up on the SharePoint Server machine. It seems easier than elevating the permissions of an anonymous user with the InfoPath code-behind option. I also tried a custom method of sending the emails but was unable to find a way to send the form data along with the email message using the InfoPath 2010 code-behind option. So, I found another way, using the advice from SharePoint UK's website.
My problem is that while removing the x-mailer header actually solved my problem regarding whole email messages, it did not allow the attached form data to be sent to the library. The message would be imported and then just disappear if I did not have the "Save original e-mail" setting enabled. Inspecting messages in the drop folder I found they had a content type of "multipart/related" and if I edited them with NotePad++ I could change that to "multipart/mixed" and the attached form data would then be imported as desired.
So I went about trying to modify the VB Script to make this happen BUT now nothing happens with the script at all. Clearly I'm doing something wrong with it and VBScript really isn't my area of expertise. Maybe it's just not possible to edit those fields or maybe I need to attack it from a different angle. How can I get my VBScript to edit the content type for these emails?
CODE:
Set shell = CreateObject("WScript.Shell")
shell.LogEvent 4, "starting mail filter"
if instr(iMsg.Fields("urn:schemas:mailheader:content-type"), "related") > 1 then
Dim logMsg = "Mail Type: " & iMsg.Fields("urn:schemas:mailheader:content-type")
Dim tempType = Replace(iMsg.Fields("urn:schemas:mailheader:content-type"), "related", "mixed")
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
iMsg.Fields.Delete("urn:schemas:mailheader:content-type")
iMsg.Fields.Item("urn:schemas:mailheader:content-type") = tempType
iMsg.Fields.Update
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
end if
shell.LogEvent 4, "end mail filter"
iMsg.DataSource.Save
EventStatus = 0
I looked into this in greater detail and found that the content-type property of an email message is one of the many that is read-only using this particular vbscript library. So, I would have to find some other way of editing the file, and the work involved is more than what it would take to find an alternate solution that skipped email altogether. Therefore, I am abandoning the plan of using email in this case. If you take something away from this, let it be that there are read-only properties for the mail message object in this script.