?
Solved

Outlook question

Posted on 2001-08-31
8
Medium Priority
?
282 Views
Last Modified: 2012-08-14
I am having an problem with Outlook 98. I am creating in VB an email message with an attachment. However I do not fill the SenderName property. I do'nt know how to since it is a read only property. I get an error from outlook which says something like "someone is trying to send an email. Could be a virus. are you sure"


I wanted to find out how I can fill the sendername value even if Outlook is not open and also do a name resolution in Outlook.

Appreciate all the help

Here is a sample code
I am using the Outlook 98 object reference

Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
 
If Len(txtemail) > 0 Then
    'Create a message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    objOutlookMsg.Display
    With objOutlookMsg
        .To = txtemail.Text
        .Subject = "Request for Quotation"
        .Body = "Dear " & txtAttention & vbNewLine & vbNewLine
        .Body = .Body & "Please quote price and delivery for the following parts" & vbNewLine
        .Body = .Body & "in the attached EXCEL spreadsheet and return" & vbNewLine
        .Body = .Body & " THANK YOU" & vbNewLine
        .Importance = olImportanceHigh
        .Attachments.Add (savestr)
        .Send
    End With
End If
 
Set objOutlook = Nothing
 
0
Comment
Question by:rian
8 Comments
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6445442
It looks like you've run into Outlook's anti-macro virus "protection".  Perhaps you would have better luck using CDO to send the mail.  

In Windows 2000 (the CDO object model is differnt in WinNT/Win9x), the code is something like:

  set objCDOMain = CreateObject ("CDO.Message")
 
  ' configure the SMTP mail options
  objCDOMain.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objCDOMain.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "yoursmtpserver.com
  objCDOMain.Configuration.Fields.Update
 
  ' configure the actual message
  objCDOMain.From = "'my name' <myname@mydomain.com>
  objCDOMain.To = "'someone else' <someone@somedomain.com>"
  objCDOMain.Subject = "my message title"  
  objCDOMain.TextBody = "this is my message!"
 
  ' send the message
  objCDOMain.Send
0
 

Author Comment

by:rian
ID: 6445453
I am not sure if you can use CDO on windows 95/98. What is the reference object. Can I use the same code in windows95/98/nt
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6445537
You would have to use different code in Win2k from win9x and Winnt... you would have to use GetVersionEx() to determine what O.S. was running...

But I think you will be best off using CDO, because it sounds like you have the Outlook patch that protects against macro viruses (and legitimate applications too, unfortuneately).

CDO ships with Win2k, so you dont have to install anything special there.  For Win 9x and NT, CDO is installed with Outlook 98.  Microsoft do not provide CDO with a redistributable license, so installing Outlook (and Exchange, I think) is the only way to get it.

The reference you use for Win9x/NT is "Microsoft CDO 1.21 Library".  The reference for Win2k is "Microsoft CDO for Windows 2000 Library".

If you want to support a range of operating systems, dont bother including the reference - just declare your object variable .. As Object and use CreateObject.

i.e.

Dim objCDOMain as object

set objCDOMain = CreateObject ("CDO.Message")

If OS=Win2k then
  ' use the win2k example from above
else
  ' use the win9x, etc code from http://support.microsoft.com/support/kb/articles/Q161/8/33.asp
end if
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6445542
Sorry, didn't mean to post that as an answer...
0
 

Expert Comment

by:ComTech
ID: 6445601
anthony_glenwright, has asked us to reject the comment.  Thought I believe his comment still shoud be considered.

Thanks all,
ComTech
Community Support
0
 

Author Comment

by:rian
ID: 6445902
I am not sure if you can use CDO on windows 95/98. What is the reference object. Can I use the same code in windows95/98/nt
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 6445904
Take a look at this article

Hitting the Outlook Security Brick Wall

...or How I Wasted Hours Trying to E-mail 1,900 Invitations

http://www.devx.com/free/newsletters/exo/exoed062201.asp
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6446982
You may be right - it may not work in Win9x - I don't know.  But it will only take a minute to try the code from:
  http://support.microsoft.com/support/kb/articles/Q161/8/33.asp

... to find out.  (I don't have a Win9x machine to try).
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question