Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send email message without email program 2

Status
Not open for further replies.

Alabaster

Programmer
Aug 11, 2001
44
CA
Does anyone know how to send an email message without having it go through the users email program?

I have a user that keeps telling me that a problem has been going on "For weeks" and waits till they are pissed before calling, I want to trap for the error and send an email to me when the problem happens. BUT, I don't want the message to sit in their outbox if they don't have their email program open.
So I am looking for something that will send mail with out going through their email program.

Thanks
Peter
 
What are you running. We are running Access 97, Outlook 98, on Windows 98, and sending e-mail over and exchange server.

In this enviroment I have something that may work. The user must have Outlook installed and configured. However they do not have to have it up and running to send a message. The code below will open outlook briefly just to send the message and then will close it again. If the user is not watching closely they will never know it happend. If you wanted you could also turn off the echo property and they would have not idea it ever happened. Let me know if this works for you and I will give you the function. The hardest questions always have the easiest answers.
 
Here you go, you will have to set a reference to Outlook 8.0, 9.0 will work but I have been having problems with it so I recommend 8.0. I am terrible about commenting my code but most of it is self explanatory, if you have any questions let me know.
Code:
Public Function SendEmail(msgTO As String, Optional msgCC As String, Optional msgSubject As String, Optional msgBody As String, Optional ImportanceHigh As Boolean = False, Optional SendNow As Boolean = False)
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
        Set objOutlook = CreateObject("Outlook.Application")
        Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
        With objOutlookMsg
            .To = msgTO
            .CC = msgCC
            .Subject = msgSubject
            .Body = msgBody
            If ImportanceHigh = False Then
                .Importance = olImportanceNormal
            Else
                .Importance = olImportanceHigh
            End If
            
            'Resolving the message removes all invalid e-mail address, this will handle up to 5 invalid email addresses
            Dim i As Integer
            i = 1
            Do While i < 5
                For Each objOutlookRecip In .Recipients
                    objOutlookRecip.Resolve
                    If Not objOutlookRecip.Resolve Then
                        objOutlookRecip.DELETE
                    End If
                Next
                i = i + 1
            Loop
            
            If SendNow = False Then
                .Display (False)
            ElseIf SendNow = True Then
                .Send
            End If
        End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
End Function
The hardest questions always have the easiest answers.
 
jtmach

I was wondering can I use this code for Lotus Notes R5????
 
If you know how you are welcome to. I have never used Lotus notes. It seems unlikely to me that it is possible. However, there are a lot of other people in this forum that know more then I do maybe one of them will see this and respond. The hardest questions always have the easiest answers.
 
Quick question:

Is there a way to mask the &quot;From&quot; part of the e-mail so that many people can send from multiple accounts, yet what I want for the &quot;From:&quot; part is to say &quot;yourhelp@company.org&quot;. I'm going to be using the above coding to send the e-mails so if it can go off of that, I would extremely appreciate it.

Thanks in advance,
Roy McCafferty
aka BanditWk

Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)

&quot;I do this because I know I can - no need to send gifts - just send me a smile to show me that I've helped.&quot; ~ seen on a cardboard sign held by Roy McCafferty on a corner in Las Vegas
 
I found a helpful site with a small program using Winsock to do that.
Item 7 is what I downloaded. Item 2 may be helpful, too. Both use Winsock.
You can also find mswinsck.ocx on the web. This gives good code for sending e-mail without an e-mail program, and you specify all the details, including From.
Item 7 above is a simplified way to do it.
 
Hi,

You can use

.SentOnBehalfOfName = &quot;username&quot;

look up on MS

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top