Results 1 to 4 of 4

Thread: Help with Macro for sending emails.

  1. #1
    Join Date
    Oct 2008
    Posts
    105

    Help with Macro for sending emails.

    Hi,

    I am trying to send emails to my friends as an alert if a condition is not satisfied. So I want a macro for the same. please give me some suggestions.

  2. #2
    Join Date
    May 2008
    Posts
    32

    Re: Help with Macro for sending emails.

    Use the send object command to the macro to create and to call the autoexec so it runs automatically when you open the database. Do you have Lotus Notes or Outlook? Suppose you want the database to open automatically then open windows scheduler in the control panel and use a task to your database, such as weekly or monthly open. These two things together will be a automatically generated email with details of a report or allow access in question be established.

  3. #3
    Join Date
    Apr 2008
    Posts
    42

    Re: Help with Macro for sending emails.

    Please have a look at this code that I found :

    Code:
    Sub SendEmail()
    
    Dim OlApp As New Outlook.Application
    Dim myNameSp As Outlook.Namespace
    Dim myInbox As Outlook.MAPIFolder
    Dim myExplorer As Outlook.Explorer
    Dim NewMail As Outlook.MailItem
    Dim OutOpen As Boolean
    
        ' Check to see if there's an explorer window open
        ' If not then open up a new one
        OutOpen = True
        Set myExplorer = OlApp.ActiveExplorer
        If TypeName(myExplorer) = "Nothing" Then
            OutOpen = False
            Set myNameSp = OlApp.GetNamespace("MAPI")
            Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
            Set myExplorer = myInbox.GetExplorer
        End If
        'myExplorer.Display ' You don't have to show Outlook to use it
    
        ' Create a new mail message item.
        Set NewMail = OlApp.CreateItem(olMailItem)
        With NewMail
            '.Display ' You don't have to show the e-mail to send it
            .Subject = "Look at this!"
            .To = "name@wherever.com"
            .Body = "This is a demonstration"
        End With
    
        'NewMail.Send
        If Not OutOpen Then OlApp.Quit
    
        'Release memory.
        Set OlApp = Nothing
        Set myNameSp = Nothing
        Set myInbox = Nothing
        Set myExplorer = Nothing
        Set NewMail = Nothing
    
    End Sub

  4. #4
    Join Date
    Oct 2008
    Posts
    76

    Re: Help with Macro for sending emails.

    Example Macro to Send E-mail Using MAPI Commands

    The following sample Visual Basic for Applications macro uses MAPI (Messaging Application Programming Interface) commands to send an e-mail message. The macro uses the InputBox function to gather information for Recipient, Subject, and E-mail message text. These functions can be replaced with valid text strings to avoid prompting the user for the information.

    Code:
    Sub MapiSendMail()
       Dim objSession As Object
       Dim objMessage As Object
       Dim objRecipient As Object
       Dim sProfile As String
       Dim sSubjPrmpt As String
       Dim sTextPrmpt As String
       Dim sEmailPrmpt As String
       Dim sMsgTitle As String
    
          ' Leaving sProfile equal to Null will
          ' force the user to select which Mapi
          ' profile to use. To keep from being
          ' prompted, you must supply a valid
          ' user profile.
          sProfile = ""
          sEmailPrmpt = "Enter valid Email Name of message recipient:"
          sSubjPrmpt = "Enter the subject line for this message:"
          sTextPrmpt = "Enter the text for this message:"
          sMsgTitle = "Mapi Macro Example"
    
          ' Create the Session Object.
          Set objSession = CreateObject("mapi.session")
    
          ' Log on using the session object.
          ' Specify a valid profile name if you want to
          ' avoid the logon dialog box.
          objSession.Logon profileName:=sProfile
    
          ' Add a new message object to the OutBox.
          Set objMessage = objSession.Outbox.Messages.Add
    
          ' Set the properties of the message object.
          objMessage.Subject = InputBox(sSubjPrmpt, sMsgTitle)
          objMessage.Text = InputBox(sTextPrmpt, sMsgTitle)
    
          ' Add a recipient object to the objMessage.Recipients collection.
          Set objRecipient = objMessage.Recipients.Add
    
          ' Set the properties of the recipient object.
          objRecipient.Name = InputBox(sEmailPrmpt, sMsgTitle)
          objRecipient.Resolve
    
          ' Send the message. Setting showDialog to False
          ' sends the message without displaying the message
          ' or requiring user intervention. A setting of True
          ' displays the message and the user must choose
          ' to Send from within the message dialog.
          objMessage.Send showDialog:=False
          MsgBox "Message sent successfully!"
    
          ' Log off using the session object.
          objSession.Logoff
       End Sub

Similar Threads

  1. Opera mail keeps sending Emails
    By Prabhukumar in forum Portable Devices
    Replies: 6
    Last Post: 09-11-2011, 08:08 PM
  2. Why my PC is sending emails from old account?
    By Fitroy in forum Technology & Internet
    Replies: 4
    Last Post: 13-06-2011, 10:35 AM
  3. Sending an Internal Emails
    By Ishaant Avasthi in forum Networking & Security
    Replies: 3
    Last Post: 24-10-2010, 06:02 AM
  4. Sending emails using Words 2007
    By KenNiuM in forum Windows Software
    Replies: 5
    Last Post: 07-07-2009, 05:02 PM
  5. Problem sending emails
    By Ettan in forum Technology & Internet
    Replies: 4
    Last Post: 12-01-2009, 11:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,048,339.68375 seconds with 17 queries