Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- From: "Stephen Plotnick" <thepla@xxxxxxxxxxxxx>
- Date: Sat, 18 Aug 2007 09:48:25 -0500
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]" <kenslovak@xxxxxxxx> wrote in message news:e0lODHN4HHA.5740@xxxxxxxxxxxxxxxxxxxxxxx
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" <thepla@xxxxxxxxxxxxx> wrote in message news:Q6ydna4vlqhhcVnbnZ2dnUVZ_q-jnZ2d@xxxxxxxxxxxxxxxWordFileName = "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")
automail("splotnick@xxxxxxxxxxxx;", "Problem with STEVE.xls" , "Please ensure spread*** 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("WellInvestments")
'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.NewLateBinding.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\Module1.vb:line 95
at DaveWellsEMAIL.Module1.Main() in C:\Users\Stephen Plotnick\Documents\Visual Studio 2005\Projects\DaveWellsEMAIL\DaveWellsEMAIL\Module1.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.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
.
- Follow-Ups:
- Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- From: Stephen Plotnick
- Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- References:
- Two problems sending an E-mail for Outlook 2007 and VB 2005
- From: Stephen Plotnick
- Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- From: Ken Slovak - [MVP - Outlook]
- Two problems sending an E-mail for Outlook 2007 and VB 2005
- Prev by Date: Re: Need help with MapiTable and EntryID/StoreID
- Next by Date: Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- Previous by thread: Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- Next by thread: Re: Two problems sending an E-mail for Outlook 2007 and VB 2005
- Index(es):
Loading