Microsoft Office Outlook 2013 - Define a delegate from my contacts - delegates

By default, in Microsoft Office Outlook 2013 I can define a delegate from the GAL (Global Address List). Is there a way to choose an entity from my contacts like can be done when sending an email?
thanks.

It looks like you are interested in the SendUsingAccount property of Outlook items. It 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

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>

address error when send email with 32bit outlook using automation

NOTE: edited from original after I discovered the outlook version was 32-bit not 64-bit.
I have a legacy 32-bit VB6 program that uses outlook 2010 32bit (full version, not express) to send email. Works perfect on many machines except one machine with windows 7 (64-bit I assume). Not sure if all windows 7 machines don't work or just this one.
If I use the automation technique or the MAPI technique (as I call them, see code below) outlook sends the email but the mail server kicks it back as undeliverable saying the recipient does not exist.
Now if the automation technique is used outlook displays no UI and the email is sent in the background.
However if the MAPI technique is used outlook opens it's compose email dialog which allows the user to edit the email prior to sending. What is interesting is that the recipient email looks fine but will fail as undeliverable if sent. However if the recipient is deleted and re-typed then the email will succeed. I believe a copy and re-paste works also.
This tells me there must be one or more hidden illegal characters in the recipient email address (nulls perhaps?). The code to do this shown below is very plain and I can't think of any obvious fix. txtTo is a vb6 string with an email address and this is the field that is causing all the problems.
The error message:
Your message did not reach some or all of the intended recipients.
Subject: a test from daryls cpu #2
Sent: 11/17/2017 8:01 PM
The following recipient(s) cannot be reached:
'someemail#gmail.com' on 11/17/2017 8:01 PM
None of your e-mail accounts could send to this recipient.
Automation 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
MAPI Technique
'Open up a MAPI session:
With frmMain.MAPISession1
.DownLoadMail = False
.Username = ""
.LogonUI = True
.SignOn
End With
With frmMain.MAPIMessages1
.SessionID = frmMain.MAPISession1.SessionID
.Compose
.MsgIndex = -1
.RecipIndex = 0
.RecipAddress = txtTo
.RecipDisplayName = txtTo
.RecipType = mapToList
If txtCC <> "" Then
.RecipIndex = 1
.RecipDisplayName = txtCC
.RecipAddress = txtCC
.RecipType = mapCcList
End If
'spaces are important! need one space for each attachment
'NOTE .MsgNoteText = " " MUST be there see.. KB173853 in microsoft
.MsgSubject = txtSubjext
.MsgNoteText = Space$(UBound(vAttach) + 1) & vbCrLf
.MsgNoteText = txtBody & vbCrLf
For i = 0 To UBound(vAttach)
.AttachmentIndex = i
.AttachmentPosition = i
.AttachmentType = mapData
.AttachmentName = GetFileFromPath(vAttach(i))
.AttachmentPathName = vAttach(i)
Next i
StatusBar1.Panels(1).Text = "Status: Sending"
.send True
End With
More Info:
I'm making some progress. The error has to do with email type in outlook not being SMTP. If on the send-to email in the outlook compose dialog you right-click on the email address then select outlook properties and change the email type to SMTP it will work. The type displayed is the email address itself, valid values seem to be 'mailto' and 'smtp'. So if I can set the email type from vb6 it should fix the error.
The 'Answer'? https://kb.intermedia.net/article/2344
I can't believe there is no fix for this...
RESOLVED!
I realize this topic is most likely of no interest to anyone programming in the 20th century but here is the fix:
.RecipAddress = "SMTP:" & txtTo
It just came to me. :)

Avoiding execution security alert in lotus notes

I created a button for polling in notes email body and then send it to a group of members for their voting. When the users, vote they get a execution security alert for each action the script. The following is the code placed in the Yes button.
Dim session As New notessession
Dim ws As New notesuiworkspace
Dim db As notesdatabase
Dim doc_poll As NotesDocument
Set db = session.getDatabase("Server Name", "ApplicationTesting/Polling.nsf")
Set doc_poll = db.CreateDocument()
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Dim doc As notesdocument
Set doc = uidoc.Document
If doc.temp(0) <> "yes" Then
v_val= ws.Prompt(3,"Family member count","No of Members ?")
Call doc.ReplaceItemValue("temp","yes")
Call doc.Save(True,True)
Call doc.Sign
Call doc.Save(True,True)
doc_poll.Form = "Fo-PollReport"
Call doc_poll.ReplaceItemValue("etxtUserName", session.CommonUserName )
Call doc_poll.ReplaceItemValue("etxtMembers", Cint(v_val))
Call doc_poll.save(True,False)
Messagebox"Your voting has been sent to HR", 64,"Voting"
Else
Messagebox "Your voting is already been sent to HR. Please contact HR directly,in case of any change in voting ",16, "Voting"
End If
How do i avoid execution security alert ?
To avoid the ECL alerts the signature that the code is signed under would need to be on their ECL list and allow the related commands that are hitting the alerts.
You could push that signature down via a policy (security settings IIRC).

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

Sending email from webpage using Outlook

I have a webpage that has a button that sends a letter on the page to an email recipent. Currently we are use Lotus Notes and with VB script, we are able to create an object of Lotus Notes and one of the properties for this object is PutInFolder. After the user clicks on the email button, the script will send the email and also put save the email in a certain folder on the user's computer. Our company is now switching over to Outlook 2007 and I'm looking to do the same thing with an Outlook object instead. Our development is local intranet only, and there are only a few users that will have access to this. Anyway, my problem is I cannot seem to find the same functionality with an Outlook Application.
I do have the send of the email currently working using this logic. Does anyone have any ideas on how to save the email in the user's outlook folder? I tried looking for a list of properties that I can call but I cannot find anything searching. Maybe I don't have the right terminalogy in the searches.
Thank you.
sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)
'Open mail, adress, attach report
dim objOutlk 'Outlook
dim objMail 'Email item
dim strMsg
const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
' Setup send to
objMail.To = sendto
' Setup send cc
If sendcc <> "" Then
objMail.cc = sendcc
End If
' Setup send bcc
If sendbcc <> "" Then
objMail.bcc = sendbcc
End If
'Set up Subject Line
objMail.subject = subject_text
'Add the body
strMsg = body_text & vbcrlf
'Add an attachments
If attachment1 <> "" Then
objMail.attachments.add(attachment1)
End If
If attachment2 <> "" Then
objMail.attachments.add(attachment2)
End If
If attachment3 <> "" Then
objMail.attachments.add(attachment3)
End If
objMail.body = strMsg
objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
'Clean up
set objMail = nothing
set objOutlk = nothing
End Sub
For future reference... I found the solution I was looking for. It wasn't too bad of a mess. Here's the modified source to replicate the Send and save email to a specific folder incase someone else comes looking. Thanks to Tester101 for the website I was looking for. Again this is vbscript imbedded in the HTML page.
sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)
'Open mail, adress, attach report
dim objOutlk 'Outlook
dim objMail 'Email item
dim strMsg
dim myInbox
const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
Set objNameSpace = objOutlk.Session
set objMail = objOutlk.createitem(olMailItem)
Set myNameSpace = objOutlk.GetNamespace("MAPI")
Set myExplorer = objOutlk.ActiveExplorer
' 6 at least on my machine pointed to the Inbox (should be the same as constant olFolderInbox). Within the Inbox I have a folder called Test
Set myExplorer.CurrentFolder = myNameSpace.GetDefaultFolder(6).Folders("Test")
Set myFolder = myExplorer.CurrentFolder
' Setup send to
objMail.To = sendto
' Setup send cc
If sendcc "" Then
objMail.cc = sendcc
End If
' Setup send bcc
If sendbcc "" Then
objMail.bcc = sendbcc
End If
'Set up Subject Line
objMail.subject = subject_text
'Add the body
strMsg = body_text & vbcrlf
'Add an attachments
If attachment1 "" Then
objMail.attachments.add(attachment1)
End If
If attachment2 "" Then
objMail.attachments.add(attachment2)
End If
If attachment3 "" Then
objMail.attachments.add(attachment3)
End If
objMail.body = strMsg
// objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
objMail.Save
objMail.Move(myFolder)
objMail.Send
'Clean up
set objMail = nothing
set objOutlk = nothing
End Sub
I found this article. It might be something tha could help.
http://www.outlookcode.com/codedetail_print.aspx?id=1041
If not this site has great resources for working with outlook.
It looks like the MailItem object has a Save method, as well as a SaveAs method. So you should be able to do something like this.
objMail.SaveAs "C:\Test.msg", 3
The 3 is to save the message in olMSG format see OlSaveAsType Enumeration.
I have a solution. We've decided to bcc the person sending the email and then use an outlook rule to move the email to the specified outlook folder. Thanks to everyone that replied.

Resources