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

Sending OWA Emails from Access 1

Status
Not open for further replies.

JTregear

Technical User
Oct 11, 2002
24
0
0
GB
In previous applications, I have used the Outlook library to create emails which can be sent via MS Outlook.

I would now like to be able to send emails via Outlook Web Access (OWA). What library should I use or how else should I create such emails within MS Access.
 
I would look into using SMTP. This feature needs to be enabled on your mail server though. You will also need a way to identify who the sender is to populate the 'from' field.

If SMTP is enabled, I have some code that might help you.

I don't know of any way to send email directly through OWA.

Good Luck,

Alex

Ignorance of certain subjects is a great part of wisdom
 
I think that Alex's suggestion is to have a look at CDO ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH - as usual, you are correct. I should not have assumed that CDO was already being used for the sends via regular outlook.

JTregear - Were you using CDO or the 'sendobject' method to send your emails?

Ignorance of certain subjects is a great part of wisdom
 
Here is the code I have previously used to create emails from within Access. I hope that answers your question.

Code:
Public Sub CreateEmail()
    
Dim Db As Database
Dim rst As Variant
Dim strSQL As String
Dim intContactID As Integer
Dim strContact As String
Dim strFirstName As String
Dim strLastName As String
Dim strEmailName As String

     
     Dim outObj As Outlook.Application
     Dim outMail As Outlook.MailItem
     Dim objFolder As Outlook.MAPIFolder
     
     Set outObj = CreateObject("outlook.application")
     Set objFolder = GetFolder("Public Folders/All Public Folders/Common Tasks")
     'The "GetFolder" procedure is used to set what the objFolder is.
     'Replace what's between the " " with your own folder list.
     Set outMail = outObj.CreateItem(olMailItem)
     
    'Record the number of the current record
    
    intContactID = Eval("[Forms]![Contacts]![ContactID]")
    txtAction = Me.Contact_Name
     
     
    strSQL = "SELECT Contacts.* " & _
    " FROM Contacts" & _
    " where (((Conacts.ContactID) = " & intContactID & "))"
   

   
    Set Db = CurrentDb
    Set rst = Db.OpenRecordset(strSQL)
     
    strFirstName = Nz(rst!FirstName)
    strLastName = Nz(rst!LastName)
    strEmailName = Nz(rst!EmailName)
    
     
     
    Set Db = Nothing
     
    outMail.Subject = "Subject Text"
    
    outMail.Importance = olImportanceHigh
    outMail.Categories = "Business"
    
    outMail.Body = "Dear " & strFirstName & vbCrLf & vbCrLf & _
    "Email text" 
    
    If IsNull(strEmailName) Or Len(strEmailName) = 0 Then
    
    Else
        outMail.Recipients.Add (strEmailName)
    End If
  
    outMail.Display
    On Error Resume Next
  
'    outMail.Move objFolder

    'Apirl 20, 2004. This code does move the task to the public folder
    'However it does not display the task before it is moved.
     
     Set outObj = Nothing
     Set outMail = Nothing
     Set objFolder = Nothing
     
End Sub
[End Code]
 
I think with slight modifications you will be able to use SMTP. However, I am not sure if you'll be able to display. Since SMTP only allows text body (to the best of my knowledge) you might be able to just display text in a message box asking if it's ok before send?

Here is a script for CDO using SMTP, you should be able to hack it up to suit your needs. Make sure that your IT department allows SMTP access to the mail server though...

Code:
Private Sub Submit_Click()

Dim cdoMail
Dim cdoCon


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'save record before proceeding

Set cdoMail = CreateObject("CDO.message")
Set cdoCon = CreateObject("CDO.Configuration")
Set iFields = cdoCon.Fields
    iFields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 'Set send method to SMTP
    iFields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "000.00.0.00" [b]'designate server to generate email from[/b]
    iFields.Update
    Set cdoMail.Configuration = cdoCon
    
If Forms("MyForm").Controls("Department").Value = "Decision Support" Then
            
    With cdoMail                'define From, To, CC, Subject and Body of Email
    
'These to/from/cc fields can be programmatically set of course
'one fun thing about SMTP is that you can send from an address that
'doesn’t exist
        .From = “DS_WorkOrder@someco.com” 
        .To = "alex@someco.com"
        .Cc = Forms("MyForm").Controls("RequestorEmail").Value
        .Subject = "New Work Order"

.TEXTBody = "A new work order has been submitted to " & _
Forms("MyForm").Controls("Department").Value & " for Job Number " & _
Forms("MyForm").Controls("JOBID").Value & Chr(13) & Chr(13) & _
"The work order control number is " & _
Forms("MyForm").Controls("WOID").Value & Chr(13) & Chr(13) & _
"Job: " & Forms("MyForm").Controls("WODescription") & Chr(13) & _
"Due: " & Forms("MyForm").Controls("DateNeeded") & Chr(13) & Chr(13) & _
 "Instructions: " & Forms("MyForm").Controls("Instructions")
     
        .Send                   'Send Notification of New work order

    End With
    
End If

MsgBox "Email Sent Successfully"

End Sub

Hope this helps, and sorry for the crappy formatting. I tried...

Alex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top