Connecting Tech Pros Worldwide Help | Site Map

Add Contact to a message being composed

Kenneth H. Young
Guest
 
Posts: n/a
#1: Nov 21 '05
I have created an application to query contact data from an LDAP server and
programtically create a new email to: contacts that had been highlithed by
the user. Now there is a request to add a contact to an email that is
currently be composed. How would one do that. Curently I am just using the
mailto: and piping in the selected users.

Thanks!


Peter Huang [MSFT]
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Add Contact to a message being composed


Hi

I did not understand your scenario very much.
Are you using outlook to compose message programming?
I think we may try to automation outlook to send message programming and
add the recipients in the to field.
Here is a link for you reference.
http://www.visualbasicforum.com/showthread.php?t=216898

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Kenneth H. Young
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Add Contact to a message being composed


OK that code works a little faster than the mailto command but I still have
the problem of adding cc: contacts after the fact.

Scenario:
1. Say I select 4 contacts in the LDAP program and then click on the mailto
button which generates a new email message.
2. Now I go back to the LDAP program and select 2 different contacts. How
would I add them to the cc: of the email that is already being composed?
3. Or say I start composing an email then open the LDAP program and wont to
add user the the email that is already being composed?

Thank you,




""Peter Huang" [MSFT]" <v-phuang@online.microsoft.com> wrote in message
news:4Jrqs6iQFHA.3376@TK2MSFTNGXA02.phx.gbl...[color=blue]
> Hi
>
> I did not understand your scenario very much.
> Are you using outlook to compose message programming?
> I think we may try to automation outlook to send message programming and
> add the recipients in the to field.
> Here is a link for you reference.
> http://www.visualbasicforum.com/showthread.php?t=216898
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>[/color]


Peter Huang [MSFT]
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Add Contact to a message being composed


Hi Kenneth,

So far I am researching the issue and I will update you with new
information ASAP.
Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Kenneth H. Young
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Add Contact to a message being composed


Thank you for looking into it, I really appreciate it. No worries about the
confusion it is difficult to explain what I am trying to do.


Once again thank you,


""Peter Huang" [MSFT]" <v-phuang@online.microsoft.com> wrote in message
news:gSme36XRFHA.2296@TK2MSFTNGXA02.phx.gbl...[color=blue]
> Hi Kenneth,
>
> So far I am researching the issue and I will update you with new
> information ASAP.
> Thanks for your understanding!
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>[/color]


Peter Huang [MSFT]
Guest
 
Posts: n/a
#6: Nov 21 '05

re: Add Contact to a message being composed


Hi

We can use the Outlook automation to get the opened outlook application and
get the current opend mail message editor instance.
e.g.
Dim olApp As Outlook.Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
olApp = GetObject(, "Outlook.Application") 'We assume the outlook
application is started, because we are modifying an composing mail message.
Dim mailInspector As Outlook.Inspector = olApp.ActiveInspector 'Get
the mail message editor instance
Dim mi As Outlook.MailItem
mi = mailInspector.CurrentItem 'Get the mailitem
mi.To += ";test;test2"
mi.CC += ";testg;dfd"
mi.BCC += ";testd;fdf"
mi.Recipients.ResolveAll()
End Sub


Here is a link.
Note Because of the Outlook E-Mail Security Update, when you run the
following procedures, you will be prompted several times for permission to
access your e-mail addresses and one prompt to send your message (see the
following screen shots). This is expected behavior. For more information,
see Security Features for Outlook 2002 and Previous Versions.
http://msdn.microsoft.com/library/de...us/dno2k3ta/ht
ml/odc_ac_olauto.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Kenneth H. Young
Guest
 
Posts: n/a
#7: Nov 21 '05

re: Add Contact to a message being composed


When I use the following code and rem out the 'mi.To += ";test;test2" it
deletes the entries that are already in the To: field. I have tried using
toVal = miTo().toString followed by mi.To += toVal but then the
mailInspector can't find the currentItem.

Any suggestions or links where I can research will be appreciated.

Thank you,


""Peter Huang" [MSFT]" <v-phuang@online.microsoft.com> wrote in message
news:5bZ152hRFHA.11204@TK2MSFTNGXA01.phx.gbl...[color=blue]
> Hi
>
> We can use the Outlook automation to get the opened outlook application
> and
> get the current opend mail message editor instance.
> e.g.
> Dim olApp As Outlook.Application
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> olApp = GetObject(, "Outlook.Application") 'We assume the outlook
> application is started, because we are modifying an composing mail
> message.
> Dim mailInspector As Outlook.Inspector = olApp.ActiveInspector 'Get
> the mail message editor instance
> Dim mi As Outlook.MailItem
> mi = mailInspector.CurrentItem 'Get the mailitem
> mi.To += ";test;test2"
> mi.CC += ";testg;dfd"
> mi.BCC += ";testd;fdf"
> mi.Recipients.ResolveAll()
> End Sub
>
>
> Here is a link.
> Note Because of the Outlook E-Mail Security Update, when you run the
> following procedures, you will be prompted several times for permission to
> access your e-mail addresses and one prompt to send your message (see the
> following screen shots). This is expected behavior. For more information,
> see Security Features for Outlook 2002 and Previous Versions.
> http://msdn.microsoft.com/library/de...us/dno2k3ta/ht
> ml/odc_ac_olauto.asp
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>[/color]


Peter Huang [MSFT]
Guest
 
Posts: n/a
#8: Nov 21 '05

re: Add Contact to a message being composed


Hi Kenneth,

It is strange.
Based on my test, the code works fine on my side. The To field will keep
its value.

Dim olApp As Outlook.Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
olApp = GetObject(, "Outlook.Application")
Dim mailInspector As Outlook.Inspector = olApp.ActiveInspector
Dim mi As Outlook.MailItem
mi = mailInspector.CurrentItem
mi.CC += ";test1;test2"
mi.BCC += ";test3;test4"
mi.Recipients.ResolveAll()
End Sub

Can you post the exact code you are using at your side?

Also have you closed or select anoher item in the outlook?
You may try to set a breakpoint in the code above to run the code line one
by one to monitor the mi.To's value.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Kenneth H. Young
Guest
 
Posts: n/a
#9: Nov 21 '05

re: Add Contact to a message being composed


Below is the code I am using. I have also tried replacing mVal with
";test1;test2" like your example and got the same results, it clears the To:
field.
Thanks

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim regSub, mailCmd, regSub2, mailCli, regVal1, regVal2, mList,
curCell As String
Dim mVal, mailApp, ProgF, mailParse1, mailParse2, mailParse3,
dilimVal, curLN As String
Dim sqlDelet As New OleDb.OleDbCommand("DELETE Employees.* FROM
Employees", Me.OleDbConnection1)
Dim Exists As Boolean
Dim response As MsgBoxResult
Dim reg As RegistryKey
Dim IsEmpty As Boolean
' Add the folowing "Enabled for Outlook clients ONLY! Cc: selected
contacts." to the tooltip for this button.
dilimVal = ";"
ProgF =
System.Environment.GetFolderPath(Environment.Speci alFolder.ProgramFiles) &
"\"
mList = ProgF & "NCST\LDAPToolSetup\mailList.txt"
If Exists = False Then
System.IO.File.Create(mList).Close()
End If
If Me.DataSet11.Employees.Count = 0 Then
MsgBox("The datagrid is empty, please perform a search!",
MsgBoxStyle.OKOnly, "Error!")
GoTo NoData
End If
Dim WriteVal As New System.IO.StreamWriter(mList)
For x As Integer = 0 To DataSet11.Employees.Count - 1
If Me.DataGrid1.IsSelected(x) = True Then
curCell = DataGrid1.Item(x, 3)
If Not curCell = "" Then
Else
curLN = DataGrid1.Item(x, 1)
MsgBox("You have selected a contact with the last name
""" & curLN & """ that has no email address. The operation is being
canceled! Please de-select the contacts without email addresses and try
again!", MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly, "WARNING!")
WriteVal.Close()
GoTo NoData
End If
WriteVal.Write(curCell & dilimVal)
Else
End If
Next
WriteVal.Close()
Dim readVal As New System.IO.StreamReader(mList)
mVal = readVal.ReadToEnd
readVal.Close()

'Add contacts to Cc: of the existing email message beign compsed.
'Try
Dim olApp As Outlook.Application
olApp = GetObject(, "Outlook.Application")
Dim mailInspector As Outlook.Inspector = olApp.ActiveInspector
Dim mi As Outlook.MailItem
mi = mailInspector.CurrentItem
mi.CC += mVal
mi.Recipients.ResolveAll()
NoData:
End Sub


Kenneth H. Young
Guest
 
Posts: n/a
#10: Nov 21 '05

re: Add Contact to a message being composed


I have noticed that if you initiate the composing of an email from my
program it performs correctly i.e. adds the selected contacts to the CC:
field and doesn't erase the To: field. If you generate a new email via
Outlook and then use my program to add contacts to the CC: field it erases
the To: field.


"Kenneth H. Young" <young@ncst.nrl.navy.mil> wrote in message
news:%23x9oHQYSFHA.508@TK2MSFTNGP12.phx.gbl...[color=blue]
> Below is the code I am using. I have also tried replacing mVal with
> ";test1;test2" like your example and got the same results, it clears the
> To: field.
> Thanks
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim regSub, mailCmd, regSub2, mailCli, regVal1, regVal2, mList,
> curCell As String
> Dim mVal, mailApp, ProgF, mailParse1, mailParse2, mailParse3,
> dilimVal, curLN As String
> Dim sqlDelet As New OleDb.OleDbCommand("DELETE Employees.* FROM
> Employees", Me.OleDbConnection1)
> Dim Exists As Boolean
> Dim response As MsgBoxResult
> Dim reg As RegistryKey
> Dim IsEmpty As Boolean
> ' Add the folowing "Enabled for Outlook clients ONLY! Cc: selected
> contacts." to the tooltip for this button.
> dilimVal = ";"
> ProgF =
> System.Environment.GetFolderPath(Environment.Speci alFolder.ProgramFiles) &
> "\"
> mList = ProgF & "NCST\LDAPToolSetup\mailList.txt"
> If Exists = False Then
> System.IO.File.Create(mList).Close()
> End If
> If Me.DataSet11.Employees.Count = 0 Then
> MsgBox("The datagrid is empty, please perform a search!",
> MsgBoxStyle.OKOnly, "Error!")
> GoTo NoData
> End If
> Dim WriteVal As New System.IO.StreamWriter(mList)
> For x As Integer = 0 To DataSet11.Employees.Count - 1
> If Me.DataGrid1.IsSelected(x) = True Then
> curCell = DataGrid1.Item(x, 3)
> If Not curCell = "" Then
> Else
> curLN = DataGrid1.Item(x, 1)
> MsgBox("You have selected a contact with the last name
> """ & curLN & """ that has no email address. The operation is being
> canceled! Please de-select the contacts without email addresses and try
> again!", MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly, "WARNING!")
> WriteVal.Close()
> GoTo NoData
> End If
> WriteVal.Write(curCell & dilimVal)
> Else
> End If
> Next
> WriteVal.Close()
> Dim readVal As New System.IO.StreamReader(mList)
> mVal = readVal.ReadToEnd
> readVal.Close()
>
> 'Add contacts to Cc: of the existing email message beign compsed.
> 'Try
> Dim olApp As Outlook.Application
> olApp = GetObject(, "Outlook.Application")
> Dim mailInspector As Outlook.Inspector = olApp.ActiveInspector
> Dim mi As Outlook.MailItem
> mi = mailInspector.CurrentItem
> mi.CC += mVal
> mi.Recipients.ResolveAll()
> NoData:
> End Sub
>[/color]


Steven Cheng[MSFT]
Guest
 
Posts: n/a
#11: Nov 21 '05

re: Add Contact to a message being composed


Thanks for your followup and the new information Kenneth,

We'll look further into this to see whether there is anything else we've
missed. Meanwhile if you got any
other findings, please feel free to post here also.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Closed Thread