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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

outlook outbox issue

Status
Not open for further replies.

WizDumb

Programmer
Nov 2, 2008
8
US
All,
I use the below code to format emails and ready them to send.
However, the emails created do not ever send.
They simply sit in the users outbox...
Shouldn't they send upon hitting send/receive? or upon outlook startup (provided the user has it set like that)?
I can delete the emails (if that makes a difference)

any ideas?

-Wiz

Dim objOutlook As Outlook.Application
Dim ns As Outlook.NameSpace
Dim Out_box As Outlook.MAPIFolder

Set objOutlook = CreateObject("Outlook.Application")
Set ns = GetNamespace("MAPI")
Set Out_box = ns.GetDefaultFolder(olFolderOutbox)


With objOutlookMsg

.To = email_Address

.subject = subj

.Body = bodyText
.Save

' Dropemails into outbox
'to avoid outlook security message

.Move Out_box


End With

Set objUtlookMsg = Nothing
Set objOutlook = Nothing
Set ns = Nothing
Set Out_box = Nothing
 
Try using the .send method rather than the .save method. You'll avoid the security message by doing what you're doing because you won't be sending emails. All you're doing is saving the message and copying it to a folder. The outbox isn't a special folder. It's just a folder so unless you specifically mark the message for sending it won't be sent.

The best option would be to use CDO rather than Outlook objects as you don't have the security/profile issues to worry about.
 
Tim,
Thank you for the response.
that is the direction I went in.

Here is the code I'm using:

Code:
Public Function sendEmail(inUser As String, toAddr As String, subj As String, body As String, Optional attach As String) As Boolean

    Dim use_ssl As Long
    Dim smtp_Port As Long
    Dim smtp_server As String
    Dim user_Email As String
    Dim send_User As String
    Dim send_Pass As String
    Dim ObjMail As Object
    Dim tSQL As String
    Dim tRS As DAO.Recordset
    
    Set ObjMail = CreateObject("CDO.Message")
      
     
     tSQL = "SELECT USERS.smtpSvr, USERS.smtpPort, USERS.UseSSL, USERS.SendUser, USERS.sendPass, USERS.emailAddr " & _
                " From Users " & _
                " WHERE (((USERS.UserId)='" & inUser & "'));"

     Set tRS = CurrentDb.OpenRecordset(tSQL)
     With tRS
        
        If Not .EOF And Not .BOF Then
            .MoveLast: .MoveFirst
            
                smtp_server = .Fields(0)
                smtp_Port = .Fields(1)
                use_ssl = .Fields(2)
                send_User = .Fields(3)
                send_Pass = .Fields(4)
                user_Email = .Fields(5)

        Else
            'ERROR
            sendmail = False
            Exit Function
        End If
        
    End With

        
    Set tRS = Nothing
        
    
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2  
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = smtp_server
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = smtp_Port
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpusessl")[/URL] = CBool(use_ssl) 
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")[/URL] = 60
         
ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")[/URL] = 1  
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] = send_User
    ObjMail.Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] = send_Pass
         
    ObjMail.Configuration.Fields.Update
         

    ObjMail.To = toAddr
    ObjMail.subject = subj
    ObjMail.From = user_Email
    
     If Nz(attach, "") <> "" Then ObjMail.AddAttachment attach

    ObjMail.TextBody = body
         
    ObjMail.Send
         
    Set ObjMail = Nothing
    
    sendEmail = True
    
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top