PDA

Click to See Complete Forum and Search --> : Erratic behaviour in Email sending by Outlook Object in VB6


mpsahuja
May 24th, 2006, 11:03 PM
I am sending emails thru Outlook object in VB6. At one stage it was sending the mails properly.
Suddenly 2 things have started happening in Outlook:

1. The default mail sending account is not geting used anymore. It shows blank there. I have set

the default settings as plain text and not to send immdly.

2. .Body of the mailitem shows its matter properly when i debug and check thru .display. But

finally when .send is executed and I see the email in Outlook outbox, it has no text in body.

I have checked that the Fildata variable which contains body text contains proper values. I am

showing the values thru messagebox and display as well. It displays properly, but once in Outlook

outbox, email body matter vanishes.

And very rarely, once in a while the body contents also stay and do not vanish. Its quite

erratic.

But sender details are always blank, even after having a valid default email account.

If somehow I attach a file using .Attachments.Add, that attachment stays properly.

3. I am using VB6, with Win Xp - pro.

4. I have even tried disabling firewall and scanning for virus etc.

5. Here's the part of the code:

Private Sub DoMailingMSOutlook()

Dim objOutlook As Object
Dim objOutlookMsg As Object

'late binding method
Set objOutlook = CreateObject("Outlook.Application")

' we use zero argument as it is for new mail message
'Appointment 1; 'Contact 2; 'Distribution List 7
'Journal 4; 'Mail Message 0; 'Note 5 'Post 6; 'Task 3

Set objOutlookMsg = objOutlook.CreateItem(0)
strSubject = "MF " & strPortfolio

With objOutlookMsg

.To = "xyz@hotmail.com"
.Subject = strSubject
If FilDat = "" Then
MsgBox "No body text for '" & strPortfolio & "'", vbInformation, g_strPackage
Else
MsgBox "There is body text for '" & strPortfolio & "'", vbInformation, g_strPackage
MsgBox "Body text is: '" & FilDat & "'", vbInformation, g_strPackage

.Body = FilDat
.Attachments.Add FilName

.display
End If

.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

6. Any suggestions on code ? And why the dafault mail account is not geting pircked up ?

Rgds

RobDog888
May 25th, 2006, 03:05 AM
Welcome to the Forums.

I see that your .Display the message and then after your doing a .Send. It may help if you display the message modally in case anything the user is doing while displayed is causing the irregularities.

Also, your not spoecifing the BodyFormat type.

What version of Outlook?


'...

objOutlookMsg.BodyFormat = 1 'olFormatPlain
objOutlookMsg.Body = "Meow.NET!"

'...
objOutlookMsg.Display vbModal

mpsahuja
May 25th, 2006, 09:53 AM
Hi, and thanx.

I am using Outlook 2002. The default body format I have taken is plain text, and from ver Outlook ver 2002 .body picks up the default text format properly. I have also checked that plain text format is getting selected correctly.

The .display as well as messageboxes have been used mainly for debugging, I dont need them in my program.

I have made .display vbModal as per your suggestion.

I have even tried some hard-coded text rather than picking up value from a variable for .body. When the mailitem gets displayed, body text is shown properly, but once Outlook security question comes at .send, the email lands up in outbox with missing body text.

One important point I missed - I am iterating thru a loop and picking up one of the portfolios for a user, and in each email message sending the portfolio details as body text. So its being run not once, but a few times, for all the portfolios of the user. I have also moved the variable declarations for outlook objects appropriately, away from this routine. I am also killing off the variables properly while exiting.

The problem persists.

Best Regards

RobDog888
May 25th, 2006, 04:25 PM
If you dont specify the bodyformat then its open to intreptation and potential issues.

objOutlookMsg.BodyFormat = 1

If your doing this in a loop then you dont need to be creating the Outlook.Application object for each iteration. Just create it once before the call to the loop and then destroy after the loop is done.

mpsahuja
May 25th, 2006, 09:33 PM
already done these two things:

objOutlookMsg.BodyFormat = 1

&

If your doing this in a loop then you dont need to be creating the Outlook.Application object for each iteration. Just create it once before the call to the loop and then destroy after the loop is done.


Still the problem is there.

I cudnt come across this sort of problem in knowledgebase. The thing is, this program was behaving earlier.

RobDog888
May 26th, 2006, 02:22 PM
Maybe you did a recent windows or Office update?

mpsahuja
May 29th, 2006, 05:03 AM
Hi, I appreciate your help all thru.

Well, I had unchecked the immediate sending option, in Outlook 2002. So with some emails in outbox with showing no body text, I decided to click send button on Outlook, and found that the emails reached destinations with all proper text in it ! So the problem is only in my outlook setup which is not showing emails properly. I cudnt figure out how to correct this in Outlook.

Now, the clients have Outlook 2000 (under xp pro), running in a different city, some 1500 kms away, so i havent seen complete system myself. In mailing module they are getting Error 429, Active X component cannot create object, pointing to Outlook. Can you guide here, as this error also needs elimination of various aspects, as per Microsoft knowledge base articlea I scanned thru. Their registery is fine, and they have run patch also, same problem persists.

Best Regards

RobDog888
May 29th, 2006, 12:39 PM
The 429 error is because the VBAProject has a default reference set to Outlook 11.0 Now if you distribute it you may have to remove the 11.0 reference and add a reference to Outlook xx.0 that they have.

Also, could be any other reference you have added like ADO 2.x if your connecting to a database, etc.