• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Outlook question

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)
    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)
    End With
End If
Set objOutlook = Nothing
1 Solution
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
  ' 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
rianAuthor Commented:
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
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.


Dim objCDOMain as object

set objCDOMain = CreateObject ("CDO.Message")

If OS=Win2k then
  ' use the win2k example from above
  ' use the win9x, etc code from http://support.microsoft.com/support/kb/articles/Q161/8/33.asp
end if
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Sorry, didn't mean to post that as an answer...
anthony_glenwright, has asked us to reject the comment.  Thought I believe his comment still shoud be considered.

Thanks all,
Community Support
rianAuthor Commented:
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
Anthony PerkinsCommented:
Take a look at this article

Hitting the Outlook Security Brick Wall

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

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:

... to find out.  (I don't have a Win9x machine to try).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now