Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

send email using outlook

Discussion in 'Information Technology' started by Richard, Jul 28, 2006.

  1. Richard

    Richard
    Expand Collapse
    Guest

    Hi

    I am using access to automate sending emails using outlook. How do I send
    emails without opening Outlook or can I?

    Many thanks in advance
    Richard
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Why This Sikh Cartoonist Is Sending A Postcard To Trump Every Day Breaking News Mar 23, 2016
    UK Statue of turbaned Sikh fighter pilot unveiled in Gravesend Breaking News Nov 29, 2014
    Leisure Appropriate to send flowers to a friend's ill Mother in India? Business, Lifestyle & Leisure Jun 6, 2013
    USA Preet Bharara Sends a Message to Wall Street about Insider Trading Breaking News May 18, 2011
    USA U.S. Sends Warning to People Named in Cable Leaks Breaking News Jan 7, 2011

  3. james.igoe@gmail.com

    james.igoe@gmail.com
    Expand Collapse
    Guest

    I have not used the following code - I usually use the Outlook Express
    client since my work is always on corporate standard clients with
    Outlook set - but it seems easy enough; you would only need to automate
    collection/setting of e-mail strings:

    **Module (space formatting added to make it easier to read):

    Public Declare Function ShellExecute Lib "shell32.dll"
    Alias "ShellExecuteA"
    (ByVal hwnd As Long,
    ByVal lpOperation As String,
    ByVal lpFile As String,
    ByVal lpParameters As String,
    ByVal lpDirectory As String,
    ByVal nShowCmd As Long)
    As Long

    '**Code attached to a button:

    Dim stext As String

    'Hard coded parts of the e-mail, stripped down to the minimum
    stext = "mailto:me@myaddress.co.nz?"
    stext = stext & "&Subject=" & "Document attached"
    stext = stext & "&Body=" & "Please find the document attached"

    'Launch default e-mail
    Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
    SW_SHOWNORMAL)


    Richard wrote:
    > Hi
    >
    > I am using access to automate sending emails using outlook. How do I send
    > emails without opening Outlook or can I?
    >
    > Many thanks in advance
    > Richard
     
  4. Richard

    Richard
    Expand Collapse
    Guest

    Hi James

    I have a code to automate using Outlook Express but I can't seem to be able
    to set attachments. Does you code allow you to set attachments?

    Thanks and regards
    Richard
    <james.igoe@gmail.com> wrote in message
    news:1150682578.650034.309690@g10g2000cwb.googlegroups.com...
    > I have not used the following code - I usually use the Outlook Express
    > client since my work is always on corporate standard clients with
    > Outlook set - but it seems easy enough; you would only need to automate
    > collection/setting of e-mail strings:
    >
    > **Module (space formatting added to make it easier to read):
    >
    > Public Declare Function ShellExecute Lib "shell32.dll"
    > Alias "ShellExecuteA"
    > (ByVal hwnd As Long,
    > ByVal lpOperation As String,
    > ByVal lpFile As String,
    > ByVal lpParameters As String,
    > ByVal lpDirectory As String,
    > ByVal nShowCmd As Long)
    > As Long
    >
    > '**Code attached to a button:
    >
    > Dim stext As String
    >
    > 'Hard coded parts of the e-mail, stripped down to the minimum
    > stext = "mailto:me@myaddress.co.nz?"
    > stext = stext & "&Subject=" & "Document attached"
    > stext = stext & "&Body=" & "Please find the document attached"
    >
    > 'Launch default e-mail
    > Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
    > SW_SHOWNORMAL)
    >
    >
    > Richard wrote:
    > > Hi
    > >
    > > I am using access to automate sending emails using outlook. How do I

    send
    > > emails without opening Outlook or can I?
    > >
    > > Many thanks in advance
    > > Richard

    >
     
  5. james.igoe@gmail.com

    james.igoe@gmail.com
    Expand Collapse
    Guest

    I haven't used the code provided; I wrote that in the first sentence.
    I do have Outlook code, and to send mail one needs to replace .Display
    with .Send in the with area. This code will allow attachments:


    Sub RequestAccess()

    Dim objOutlookApp As Object
    Dim objOutlookMail As Object

    Set objOutlookApp = CreateObject("Outlook.Application")
    Set objOutlookMail = objOutlookApp.CreateItem(0)

    Dim strRecipients As String
    Dim CurrentUser As String

    strRecipients = "[Put you recipients here]"

    With objOutlookMail
    .To = strRecipients
    .Subject = "Request..."
    .Display
    End With

    'releases resources from outlook and associated components
    If Not objOutlookApp Is Nothing Then

    objOutlookApp.Quit

    If Not objOutlookMail Is Nothing Then
    Set objOutlookMail = Nothing
    End If

    Set objOutlookApp = Nothing

    End If

    Exit Sub

    ErrorTrap:

    MsgBox Err.Number & " : " & Err.Description, vbOKOnly, "Error"

    'releases resources from outlook and associated components
    If Not objOutlookApp Is Nothing Then

    objOutlookApp.Quit

    If Not objOutlookMail Is Nothing Then
    Set objOutlookMail = Nothing
    End If

    Set objOutlookApp = Nothing

    End If

    End Sub



    Richard wrote:
    > Hi James
    >
    > I have a code to automate using Outlook Express but I can't seem to be able
    > to set attachments. Does you code allow you to set attachments?
    >
    > Thanks and regards
    > Richard
    > <james.igoe@gmail.com> wrote in message
    > news:1150682578.650034.309690@g10g2000cwb.googlegroups.com...
    > > I have not used the following code - I usually use the Outlook Express
    > > client since my work is always on corporate standard clients with
    > > Outlook set - but it seems easy enough; you would only need to automate
    > > collection/setting of e-mail strings:
    > >
    > > **Module (space formatting added to make it easier to read):
    > >
    > > Public Declare Function ShellExecute Lib "shell32.dll"
    > > Alias "ShellExecuteA"
    > > (ByVal hwnd As Long,
    > > ByVal lpOperation As String,
    > > ByVal lpFile As String,
    > > ByVal lpParameters As String,
    > > ByVal lpDirectory As String,
    > > ByVal nShowCmd As Long)
    > > As Long
    > >
    > > '**Code attached to a button:
    > >
    > > Dim stext As String
    > >
    > > 'Hard coded parts of the e-mail, stripped down to the minimum
    > > stext = "mailto:me@myaddress.co.nz?"
    > > stext = stext & "&Subject=" & "Document attached"
    > > stext = stext & "&Body=" & "Please find the document attached"
    > >
    > > 'Launch default e-mail
    > > Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
    > > SW_SHOWNORMAL)
    > >
    > >
    > > Richard wrote:
    > > > Hi
    > > >
    > > > I am using access to automate sending emails using outlook. How do I

    > send
    > > > emails without opening Outlook or can I?
    > > >
    > > > Many thanks in advance
    > > > Richard

    > >
     
  6. Richard

    Richard
    Expand Collapse
    Guest

    Thanks James

    Appreciate your help and time

    Richard

    <james.igoe@gmail.com> wrote in message
    news:1150797655.456630.190680@r2g2000cwb.googlegroups.com...
    >
    > I haven't used the code provided; I wrote that in the first sentence.
    > I do have Outlook code, and to send mail one needs to replace .Display
    > with .Send in the with area. This code will allow attachments:
    >
    >
    > Sub RequestAccess()
    >
    > Dim objOutlookApp As Object
    > Dim objOutlookMail As Object
    >
    > Set objOutlookApp = CreateObject("Outlook.Application")
    > Set objOutlookMail = objOutlookApp.CreateItem(0)
    >
    > Dim strRecipients As String
    > Dim CurrentUser As String
    >
    > strRecipients = "[Put you recipients here]"
    >
    > With objOutlookMail
    > .To = strRecipients
    > .Subject = "Request..."
    > .Display
    > End With
    >
    > 'releases resources from outlook and associated components
    > If Not objOutlookApp Is Nothing Then
    >
    > objOutlookApp.Quit
    >
    > If Not objOutlookMail Is Nothing Then
    > Set objOutlookMail = Nothing
    > End If
    >
    > Set objOutlookApp = Nothing
    >
    > End If
    >
    > Exit Sub
    >
    > ErrorTrap:
    >
    > MsgBox Err.Number & " : " & Err.Description, vbOKOnly, "Error"
    >
    > 'releases resources from outlook and associated components
    > If Not objOutlookApp Is Nothing Then
    >
    > objOutlookApp.Quit
    >
    > If Not objOutlookMail Is Nothing Then
    > Set objOutlookMail = Nothing
    > End If
    >
    > Set objOutlookApp = Nothing
    >
    > End If
    >
    > End Sub
    >
    >
    >
    > Richard wrote:
    > > Hi James
    > >
    > > I have a code to automate using Outlook Express but I can't seem to be

    able
    > > to set attachments. Does you code allow you to set attachments?
    > >
    > > Thanks and regards
    > > Richard
    > > <james.igoe@gmail.com> wrote in message
    > > news:1150682578.650034.309690@g10g2000cwb.googlegroups.com...
    > > > I have not used the following code - I usually use the Outlook Express
    > > > client since my work is always on corporate standard clients with
    > > > Outlook set - but it seems easy enough; you would only need to

    automate
    > > > collection/setting of e-mail strings:
    > > >
    > > > **Module (space formatting added to make it easier to read):
    > > >
    > > > Public Declare Function ShellExecute Lib "shell32.dll"
    > > > Alias "ShellExecuteA"
    > > > (ByVal hwnd As Long,
    > > > ByVal lpOperation As String,
    > > > ByVal lpFile As String,
    > > > ByVal lpParameters As String,
    > > > ByVal lpDirectory As String,
    > > > ByVal nShowCmd As Long)
    > > > As Long
    > > >
    > > > '**Code attached to a button:
    > > >
    > > > Dim stext As String
    > > >
    > > > 'Hard coded parts of the e-mail, stripped down to the minimum
    > > > stext = "mailto:me@myaddress.co.nz?"
    > > > stext = stext & "&Subject=" & "Document attached"
    > > > stext = stext & "&Body=" & "Please find the document attached"
    > > >
    > > > 'Launch default e-mail
    > > > Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
    > > > SW_SHOWNORMAL)
    > > >
    > > >
    > > > Richard wrote:
    > > > > Hi
    > > > >
    > > > > I am using access to automate sending emails using outlook. How do I

    > > send
    > > > > emails without opening Outlook or can I?
    > > > >
    > > > > Many thanks in advance
    > > > > Richard
    > > >

    >
     
  7. Ron2006

    Ron2006
    Expand Collapse
    Guest

    The following will work: (use only the parts of the email message that
    you need). These are all of the aspects of outlook email that I have
    found so far.

    This assums the button name is command0.
    If Outlook is NOT open when this is done, then the email simply goes
    into the outbox.

    ==============================
    Private Sub Command0_Click()
    On Error GoTo Error_Handler

    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem

    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)

    With objEmail
    .To = "info@datastrat.com"
    .CC = "secondemailadd@hotmail.com"
    .BCC = "blindcopyaddress@coldmail.com"
    .Subject = "Look at this sample attachment"
    .body = "The body doesn't matter, just the attachment"
    .Attachments.Add "C:\Test.htm"
    '.attachments.Add "c:\Path\to\the\next\file.txt"

    ' ========================================
    ' next two only if the body is to include HTML

    .bodyformat = 2 ' not necessary if no html this makes
    it html
    ' 1 is text 2 is
    HTML 3 is RTF
    .htmlbody = Chr(13) & Chr(13) & _
    "<body>" & _
    "<Table>" &_
    "<tr>" &_
    "<td><b> Date: </b></td>" & _
    "<td>" & Date & "</td>" & _
    "</tr>" &_
    "<tr>" &_
    "<td></td>" & _
    "<td></td>" & _
    "</tr>" &_
    " </Table>" &_
    "</body>"

    '==============================

    .Send
    '.ReadReceiptRequested
    '.Display ' to see the email have have user actually do the
    send
    ' don't use the .Send if you are using
    Display


    '
    End With

    Exit_Here:
    Set objOutlook = Nothing
    Exit Sub

    Error_Handler:
    MsgBox Err & ": " & Err.Description
    Resume Exit_Here

    End Sub
    ===================================
     

Share This Page