A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Two problems sending an E-mail for Outlook 2007 and VB 2005



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 17th 07, 01:33 AM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

WordFileName = "C:\temp\Steve.HTM"

Dim WordContent As String

Dim AppWord As New Microsoft.Office.Interop.Word.ApplicationClass

With AppWord
.Visible = False
.ScreenUpdating = False
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With

Dim WordDoc As Microsoft.Office.Interop.Word.Document
WordDoc = AppWord.Documents.Open(CType(WordFileName, Object))
WordDoc.Content.Select()
WordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()

If objClipboard.GetDataPresent(DataFormats.Html) Then
WordContent = objClipboard.GetData(DataFormats.Html)
Else
WordContent = "XXX"
End If

WordDoc.Close()
WordDoc = Nothing
AppWord.Quit()

Filename = "C:\temp\IL Broker List.xls"
If Not File.Exists(Filename) Then
Console.WriteLine("E-mail name and address file does not exist")
;", "Problem with STEVE.xls" ,
"Please ensure spreadsheet of E-mail address is in the C:\TEMP directory",
WordFileName)
Else
Console.WriteLine("Sending documents")
obook = GetObject("C:\TEMP\STEVE.xls")
Dim irow As Integer
Dim SendPersonName As String
For irow = 2 To 25000
If obook.Worksheets(1).Cells(irow, 1).value "" Then
'MsgBox(obook.Worksheets(1).Cells(irow, icol).Value)
SendPersonName = obook.Worksheets(1).cells(irow,
2).value & " " & obook.Worksheets(1).cells(irow, 3).value
Console.WriteLine(SendPersonName)
automail(obook.Worksheets(1).Cells(irow, 1).value,
"Looking To Buy Investment Propert ", WordContent, WordFileName)
Else
irow = 25000
End If
Next
End If
Close_rtn()
End Sub

Public Sub automail(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)
Dim myOutlook As New Outlook.Application()
Dim myMailItem, attach As Object
myMailItem = myOutlook.CreateItem(Outlook.OlItemType.olMailItem )
myMailItem.HTMLbody = msg


If File.Exists(filename) Then
attach = myMailItem.Attachments
'DO NOT Send the attachement
'attach.Add(filename)
End If

If Trim(mail_to) "" Then
myMailItem.To = Trim(mail_to)
End If

myMailItem.SendUsingAccount =
myOutlook.Application.Session.Accounts("WellInvest ments")
'myMailItem.SendUsingAccount = "WellInvestments"

subject = subject
myMailItem.Subject = subject
myMailItem.Send()
myMailItem = Nothing
myOutlook = Nothing
End Sub

Problem 1:
In the SendUsingAccount (not commented) I get the error below.
In the SendUsingAccount (commented out) the program processes but it sends
out from ny default E-mail.

Problem 2:
I have a Word Docement that I want to get the information into the body of
the E-mail. There is simple formatting, like bold and undeline. I've tried
"DOC", "DOCX", "RTF", "HTM". I cannot get the text to look correct. It is
either non formatted text or ends up having all kinds of HTML code.

Thanks in advance for assistance,
Steve


System.Reflection.TargetParameterCountException was unhandled
Message="Number of parameters specified does not match the expected
number."
Source="Microsoft.VisualBasic"
StackTrace:
at Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at DaveWellsEMAIL.Module1.automail(String mail_to, String subject,
String msg, String filename) in C:\Users\Stephen Plotnick\Documents\Visual
Studio 2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 95
at DaveWellsEMAIL.Module1.Main() in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 69
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Ads
  #2  
Old August 17th 07, 02:10 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

Is the HTML in the Word doc correctly formatted? Look at it and an HTML
message and try to see where the HTML is not the same.

I'd suspect that you aren't getting a valid Account object, I've used
SendUsingAccount with valid Account objects with no problems, although
reading that object property only works right in a Send event. Try getting
an Account object using one of your formulations and see if you do get a
valid Account object or if it's Nothing.

I'd also make sure to resolve all recipients as a matter of good practice:
myMailItem.Recipients.ResolveAll

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
WordFileName = "C:\temp\Steve.HTM"

Dim WordContent As String

Dim AppWord As New Microsoft.Office.Interop.Word.ApplicationClass

With AppWord
.Visible = False
.ScreenUpdating = False
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With

Dim WordDoc As Microsoft.Office.Interop.Word.Document
WordDoc = AppWord.Documents.Open(CType(WordFileName, Object))
WordDoc.Content.Select()
WordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()

If objClipboard.GetDataPresent(DataFormats.Html) Then
WordContent = objClipboard.GetData(DataFormats.Html)
Else
WordContent = "XXX"
End If

WordDoc.Close()
WordDoc = Nothing
AppWord.Quit()

Filename = "C:\temp\IL Broker List.xls"
If Not File.Exists(Filename) Then
Console.WriteLine("E-mail name and address file does not
exist")
;", "Problem with STEVE.xls" ,
"Please ensure spreadsheet of E-mail address is in the C:\TEMP directory",
WordFileName)
Else
Console.WriteLine("Sending documents")
obook = GetObject("C:\TEMP\STEVE.xls")
Dim irow As Integer
Dim SendPersonName As String
For irow = 2 To 25000
If obook.Worksheets(1).Cells(irow, 1).value "" Then
'MsgBox(obook.Worksheets(1).Cells(irow, icol).Value)
SendPersonName = obook.Worksheets(1).cells(irow,
2).value & " " & obook.Worksheets(1).cells(irow, 3).value
Console.WriteLine(SendPersonName)
automail(obook.Worksheets(1).Cells(irow, 1).value,
"Looking To Buy Investment Propert ", WordContent, WordFileName)
Else
irow = 25000
End If
Next
End If
Close_rtn()
End Sub

Public Sub automail(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)
Dim myOutlook As New Outlook.Application()
Dim myMailItem, attach As Object
myMailItem = myOutlook.CreateItem(Outlook.OlItemType.olMailItem )
myMailItem.HTMLbody = msg


If File.Exists(filename) Then
attach = myMailItem.Attachments
'DO NOT Send the attachement
'attach.Add(filename)
End If

If Trim(mail_to) "" Then
myMailItem.To = Trim(mail_to)
End If

myMailItem.SendUsingAccount =
myOutlook.Application.Session.Accounts("WellInvest ments")
'myMailItem.SendUsingAccount = "WellInvestments"

subject = subject
myMailItem.Subject = subject
myMailItem.Send()
myMailItem = Nothing
myOutlook = Nothing
End Sub

Problem 1:
In the SendUsingAccount (not commented) I get the error below.
In the SendUsingAccount (commented out) the program processes but it sends
out from ny default E-mail.

Problem 2:
I have a Word Docement that I want to get the information into the body of
the E-mail. There is simple formatting, like bold and undeline. I've tried
"DOC", "DOCX", "RTF", "HTM". I cannot get the text to look correct. It is
either non formatted text or ends up having all kinds of HTML code.

Thanks in advance for assistance,
Steve


System.Reflection.TargetParameterCountException was unhandled
Message="Number of parameters specified does not match the expected
number."
Source="Microsoft.VisualBasic"
StackTrace:
at Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at DaveWellsEMAIL.Module1.automail(String mail_to, String subject,
String msg, String filename) in C:\Users\Stephen Plotnick\Documents\Visual
Studio 2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 95
at DaveWellsEMAIL.Module1.Main() in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 69
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


  #3  
Old August 18th 07, 03:48 PM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

myMailItem.Recipients.ResolveAll()

myMailItem.SendUsingAccount = "WellInvestments"

The WellInvestments is the name I've given to this E-mail account. In
Outlook 2007 under tools-Account Settings "WellInvestments" is under the
name field. I have three other accounts and this one is the last one in the
list; it is also not the default one. The default one is on the top and also
the one that my program shows as the E-mail client that is going to be used
for sending the E-mails.

I'll work on the Word problem later. I've tried everything that I've read
and I can go to an E-mail and create one manually and hit the CTRL-V to
paster manaully (my program still has the Word doc in the clipboard) and it
looks perfect. I just can't get the thing to get it there programmatically.

THanks,
Steve



"Ken Slovak - [MVP - Outlook]" wrote in message
...
Is the HTML in the Word doc correctly formatted? Look at it and an HTML
message and try to see where the HTML is not the same.

I'd suspect that you aren't getting a valid Account object, I've used
SendUsingAccount with valid Account objects with no problems, although
reading that object property only works right in a Send event. Try getting
an Account object using one of your formulations and see if you do get a
valid Account object or if it's Nothing.

I'd also make sure to resolve all recipients as a matter of good practice:
myMailItem.Recipients.ResolveAll

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
WordFileName = "C:\temp\Steve.HTM"

Dim WordContent As String

Dim AppWord As New Microsoft.Office.Interop.Word.ApplicationClass

With AppWord
.Visible = False
.ScreenUpdating = False
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With

Dim WordDoc As Microsoft.Office.Interop.Word.Document
WordDoc = AppWord.Documents.Open(CType(WordFileName, Object))
WordDoc.Content.Select()
WordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()

If objClipboard.GetDataPresent(DataFormats.Html) Then
WordContent = objClipboard.GetData(DataFormats.Html)
Else
WordContent = "XXX"
End If

WordDoc.Close()
WordDoc = Nothing
AppWord.Quit()

Filename = "C:\temp\IL Broker List.xls"
If Not File.Exists(Filename) Then
Console.WriteLine("E-mail name and address file does not
exist")
;", "Problem with STEVE.xls"
, "Please ensure spreadsheet of E-mail address is in the C:\TEMP
directory", WordFileName)
Else
Console.WriteLine("Sending documents")
obook = GetObject("C:\TEMP\STEVE.xls")
Dim irow As Integer
Dim SendPersonName As String
For irow = 2 To 25000
If obook.Worksheets(1).Cells(irow, 1).value "" Then
'MsgBox(obook.Worksheets(1).Cells(irow, icol).Value)
SendPersonName = obook.Worksheets(1).cells(irow,
2).value & " " & obook.Worksheets(1).cells(irow, 3).value
Console.WriteLine(SendPersonName)
automail(obook.Worksheets(1).Cells(irow, 1).value,
"Looking To Buy Investment Propert ", WordContent, WordFileName)
Else
irow = 25000
End If
Next
End If
Close_rtn()
End Sub

Public Sub automail(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)
Dim myOutlook As New Outlook.Application()
Dim myMailItem, attach As Object
myMailItem = myOutlook.CreateItem(Outlook.OlItemType.olMailItem )
myMailItem.HTMLbody = msg


If File.Exists(filename) Then
attach = myMailItem.Attachments
'DO NOT Send the attachement
'attach.Add(filename)
End If

If Trim(mail_to) "" Then
myMailItem.To = Trim(mail_to)
End If

myMailItem.SendUsingAccount =
myOutlook.Application.Session.Accounts("WellInvest ments")
'myMailItem.SendUsingAccount = "WellInvestments"

subject = subject
myMailItem.Subject = subject
myMailItem.Send()
myMailItem = Nothing
myOutlook = Nothing
End Sub

Problem 1:
In the SendUsingAccount (not commented) I get the error below.
In the SendUsingAccount (commented out) the program processes but it
sends out from ny default E-mail.

Problem 2:
I have a Word Docement that I want to get the information into the body
of the E-mail. There is simple formatting, like bold and undeline. I've
tried "DOC", "DOCX", "RTF", "HTM". I cannot get the text to look correct.
It is either non formatted text or ends up having all kinds of HTML code.

Thanks in advance for assistance,
Steve


System.Reflection.TargetParameterCountException was unhandled
Message="Number of parameters specified does not match the expected
number."
Source="Microsoft.VisualBasic"
StackTrace:
at
Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o, Type
objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at DaveWellsEMAIL.Module1.automail(String mail_to, String subject,
String msg, String filename) in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 95
at DaveWellsEMAIL.Module1.Main() in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 69
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



  #4  
Old August 18th 07, 04:51 PM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

Maybe this will help.

I copied a routine I found that I was going to use to "find" the accout
names. I added it to my program and get a an error "Type 'Outlook.Account'
not defined". Maybe I'm not setting up something properly.

Sub SendUsingAccount()

Dim myOutlook As New Outlook.Application()
-- I needed to add this line
Dim oAccount As Outlook.Account
-- this line gets little green underline
For Each oAccount In myOutlook.Application.Session.Accounts
-- I needed to add myOutlook to the front of "Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
")
oMail.Recipients.ResolveAll()
oMail.SendUsingAccount = oAccount
oMail.Send()
End If
Next
End Sub

  #5  
Old August 18th 07, 06:56 PM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

After trying to resolve this problem I found a solution.

Sub SendUsingAccount(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)

Dim myOutlook As New Outlook.Application()
Dim OutNS = myOutlook.GetNamespace("MAPI")
OutNS.Logon()
Dim oAccount = OutNS.Accounts
Dim ctr As Integer = 1

For Each oAccount In myOutlook.Application.Session.Accounts
Dim oMail As Outlook.MailItem
oMail =
myOutlook.Application.CreateItem(Outlook.OlItemTyp e.olMailItem)
oMail.HTMLBody = msg

If Trim(mail_to) "" Then
oMail.To = Trim(mail_to)
End If
subject = subject
oMail.Subject = subject
oMail.Recipients.ResolveAll()
oMail.SendUsingAccount = oAccount
If ctr = 2 Then
oMail.Send()
End If
ctr = ctr + 1
Next
End Sub

This method requires I know that the account order (I need the second one in
my example); I wish there was a way to find the actual value for "oAccount"
so I could define the SendUsingAccount as the actual Name. I also never
could figure how to resolve the olPop3 not defined. I ended up taking it out
of the check; you can see what I'm talking about below.

Steve

"Stephen Plotnick" wrote in message
...
Maybe this will help.

I copied a routine I found that I was going to use to "find" the accout
names. I added it to my program and get a an error "Type 'Outlook.Account'
not defined". Maybe I'm not setting up something properly.

Sub SendUsingAccount()

Dim myOutlook As New Outlook.Application() -- I needed to add this
line
Dim oAccount As Outlook.Account -- this line gets little green
underline
For Each oAccount In myOutlook.Application.Session.Accounts -- I
needed to add myOutlook to the front of "Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
")
oMail.Recipients.ResolveAll()
oMail.SendUsingAccount = oAccount
oMail.Send()
End If
Next
End Sub


  #6  
Old August 18th 07, 07:40 PM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

Working on my Word to body of text problem.

The contents being populated in the Clipboard from the Word document are
perfect. I can go to Outlook and create a new E-mail. GO to the body of the
E_mail an hit CTRL-V. The results are perfect.

No matter what I do for .DataFormats I cannot get the transfer to work.

If I use .DataFormats.Text I get a text version without any formatting.
If I use .DataFormats.HTML I get all kinds of HTML code - unreadable
If I use .DataFormats.RTF I get all kinds of garbage - unreadsble.

My origianl Doc has been converted to HTM, DOCX, and RTF and I've tried all
these combinations; nothing seems to work.

Isn't there a way to just copy from the clipboard to the body of the E-mail;
replicating the CTRL-V which works great.

THanks,
Steve



"Ken Slovak - [MVP - Outlook]" wrote in message
...
Is the HTML in the Word doc correctly formatted? Look at it and an HTML
message and try to see where the HTML is not the same.

I'd suspect that you aren't getting a valid Account object, I've used
SendUsingAccount with valid Account objects with no problems, although
reading that object property only works right in a Send event. Try getting
an Account object using one of your formulations and see if you do get a
valid Account object or if it's Nothing.

I'd also make sure to resolve all recipients as a matter of good practice:
myMailItem.Recipients.ResolveAll

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
WordFileName = "C:\temp\Steve.HTM"

Dim WordContent As String

Dim AppWord As New Microsoft.Office.Interop.Word.ApplicationClass

With AppWord
.Visible = False
.ScreenUpdating = False
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With

Dim WordDoc As Microsoft.Office.Interop.Word.Document
WordDoc = AppWord.Documents.Open(CType(WordFileName, Object))
WordDoc.Content.Select()
WordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()

If objClipboard.GetDataPresent(DataFormats.Html) Then
WordContent = objClipboard.GetData(DataFormats.Html)
Else
WordContent = "XXX"
End If

WordDoc.Close()
WordDoc = Nothing
AppWord.Quit()

Filename = "C:\temp\IL Broker List.xls"
If Not File.Exists(Filename) Then
Console.WriteLine("E-mail name and address file does not
exist")
;", "Problem with STEVE.xls"
, "Please ensure spreadsheet of E-mail address is in the C:\TEMP
directory", WordFileName)
Else
Console.WriteLine("Sending documents")
obook = GetObject("C:\TEMP\STEVE.xls")
Dim irow As Integer
Dim SendPersonName As String
For irow = 2 To 25000
If obook.Worksheets(1).Cells(irow, 1).value "" Then
'MsgBox(obook.Worksheets(1).Cells(irow, icol).Value)
SendPersonName = obook.Worksheets(1).cells(irow,
2).value & " " & obook.Worksheets(1).cells(irow, 3).value
Console.WriteLine(SendPersonName)
automail(obook.Worksheets(1).Cells(irow, 1).value,
"Looking To Buy Investment Propert ", WordContent, WordFileName)
Else
irow = 25000
End If
Next
End If
Close_rtn()
End Sub

Public Sub automail(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)
Dim myOutlook As New Outlook.Application()
Dim myMailItem, attach As Object
myMailItem = myOutlook.CreateItem(Outlook.OlItemType.olMailItem )
myMailItem.HTMLbody = msg


If File.Exists(filename) Then
attach = myMailItem.Attachments
'DO NOT Send the attachement
'attach.Add(filename)
End If

If Trim(mail_to) "" Then
myMailItem.To = Trim(mail_to)
End If

myMailItem.SendUsingAccount =
myOutlook.Application.Session.Accounts("WellInvest ments")
'myMailItem.SendUsingAccount = "WellInvestments"

subject = subject
myMailItem.Subject = subject
myMailItem.Send()
myMailItem = Nothing
myOutlook = Nothing
End Sub

Problem 1:
In the SendUsingAccount (not commented) I get the error below.
In the SendUsingAccount (commented out) the program processes but it
sends out from ny default E-mail.

Problem 2:
I have a Word Docement that I want to get the information into the body
of the E-mail. There is simple formatting, like bold and undeline. I've
tried "DOC", "DOCX", "RTF", "HTM". I cannot get the text to look correct.
It is either non formatted text or ends up having all kinds of HTML code.

Thanks in advance for assistance,
Steve


System.Reflection.TargetParameterCountException was unhandled
Message="Number of parameters specified does not match the expected
number."
Source="Microsoft.VisualBasic"
StackTrace:
at
Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o, Type
objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at DaveWellsEMAIL.Module1.automail(String mail_to, String subject,
String msg, String filename) in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 95
at DaveWellsEMAIL.Module1.Main() in C:\Users\Stephen
Plotnick\Documents\Visual Studio
2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module 1.vb:line 69
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



  #7  
Old August 20th 07, 04:19 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

Where is this code supposed to run, is it a shared addin or a VSTO addin or
standalone code?

Something is wrong with your references or something, I can reference
Outlook.Account in a declaration with no errors and I can retrieve an
account by name using olApp.Session.Accounts.Item("myAccountName") where
"myAccountName" is the DisplayName of the account I want.



--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
Maybe this will help.

I copied a routine I found that I was going to use to "find" the accout
names. I added it to my program and get a an error "Type 'Outlook.Account'
not defined". Maybe I'm not setting up something properly.

Sub SendUsingAccount()

Dim myOutlook As New Outlook.Application() -- I needed to add this
line
Dim oAccount As Outlook.Account -- this line gets little green
underline
For Each oAccount In myOutlook.Application.Session.Accounts -- I
needed to add myOutlook to the front of "Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
")
oMail.Recipients.ResolveAll()
oMail.SendUsingAccount = oAccount
oMail.Send()
End If
Next
End Sub


  #8  
Old August 20th 07, 04:21 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

That code looks wrong. How can you declare an oAccount object as
NameSpace.Accounts and then iterate the Accounts collection using that
Accounts collection object to retrieve an Account object?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
After trying to resolve this problem I found a solution.

Sub SendUsingAccount(ByVal mail_to As String, ByVal subject As String,
ByVal msg As String, ByVal filename As String)

Dim myOutlook As New Outlook.Application()
Dim OutNS = myOutlook.GetNamespace("MAPI")
OutNS.Logon()
Dim oAccount = OutNS.Accounts
Dim ctr As Integer = 1

For Each oAccount In myOutlook.Application.Session.Accounts
Dim oMail As Outlook.MailItem
oMail =
myOutlook.Application.CreateItem(Outlook.OlItemTyp e.olMailItem)
oMail.HTMLBody = msg

If Trim(mail_to) "" Then
oMail.To = Trim(mail_to)
End If
subject = subject
oMail.Subject = subject
oMail.Recipients.ResolveAll()
oMail.SendUsingAccount = oAccount
If ctr = 2 Then
oMail.Send()
End If
ctr = ctr + 1
Next
End Sub

This method requires I know that the account order (I need the second one
in my example); I wish there was a way to find the actual value for
"oAccount" so I could define the SendUsingAccount as the actual Name. I
also never could figure how to resolve the olPop3 not defined. I ended up
taking it out of the check; you can see what I'm talking about below.

Steve


  #9  
Old August 20th 07, 04:23 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

I don't understand why you're messing around with the clipboard and worrying
about clipboard formats. Can't you just get the content of that Word doc as
a text string and pass that string along as the HTMLBody?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
Working on my Word to body of text problem.

The contents being populated in the Clipboard from the Word document are
perfect. I can go to Outlook and create a new E-mail. GO to the body of
the E_mail an hit CTRL-V. The results are perfect.

No matter what I do for .DataFormats I cannot get the transfer to work.

If I use .DataFormats.Text I get a text version without any formatting.
If I use .DataFormats.HTML I get all kinds of HTML code - unreadable
If I use .DataFormats.RTF I get all kinds of garbage - unreadsble.

My origianl Doc has been converted to HTM, DOCX, and RTF and I've tried
all these combinations; nothing seems to work.

Isn't there a way to just copy from the clipboard to the body of the
E-mail; replicating the CTRL-V which works great.

THanks,
Steve


  #10  
Old August 20th 07, 10:56 PM posted to microsoft.public.outlook.program_vba
Stephen Plotnick
external usenet poster
 
Posts: 15
Default Two problems sending an E-mail for Outlook 2007 and VB 2005

How do you get the contents as a text string?

Steve
"Ken Slovak - [MVP - Outlook]" wrote in message
...
I don't understand why you're messing around with the clipboard and
worrying about clipboard formats. Can't you just get the content of that
Word doc as a text string and pass that string along as the HTMLBody?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Stephen Plotnick" wrote in message
...
Working on my Word to body of text problem.

The contents being populated in the Clipboard from the Word document are
perfect. I can go to Outlook and create a new E-mail. GO to the body of
the E_mail an hit CTRL-V. The results are perfect.

No matter what I do for .DataFormats I cannot get the transfer to work.

If I use .DataFormats.Text I get a text version without any formatting.
If I use .DataFormats.HTML I get all kinds of HTML code - unreadable
If I use .DataFormats.RTF I get all kinds of garbage - unreadsble.

My origianl Doc has been converted to HTM, DOCX, and RTF and I've tried
all these combinations; nothing seems to work.

Isn't there a way to just copy from the clipboard to the body of the
E-mail; replicating the CTRL-V which works great.

THanks,
Steve



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2007: Problems with HTML e-mail formatting [email protected] Outlook - General Queries 0 May 4th 07 11:25 AM
Outlook 2007 Add-in using VSTO 2005 SE Kenn Outlook - Using Forms 1 November 4th 06 03:27 AM
Problems Sending Mail Via Dialup WarpGammon Director Outlook - General Queries 2 October 10th 06 09:06 PM
Problems sending mail via sub folder in Outlook 2003 wn Outlook - Installation 1 August 16th 06 04:46 PM
Sending keys from vb.2005 to Outlook Al Christoph Outlook - Using Forms 1 May 1st 06 05:18 PM


All times are GMT +1. The time now is 02:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.