Results 1 to 10 of 10

Thread: daily send email Outlook with attach

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2015
    Posts
    5

    daily send email Outlook with attach

    Hello all,

    I'm new at this forum. I know somethings about VBA on excel (not much but i can understand them) but i dont know nothing about VBA on Outlook.

    Here is my case.....

    I need to send 5 emails every day all of them with attach and the attachements are everytime in the desktop with the same name. the emails are everyday the same.

    Can that be done with a vba ???

    Thansk in advance
    (sorry for my bad english)
    mdorey

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: daily send email Outlook with attach

    Can that be done with a vba ???
    yes of course
    at specific times?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2015
    Posts
    5

    Re: daily send email Outlook with attach

    Quote Originally Posted by westconn1 View Post
    yes of course
    at specific times?
    If that is possible without a specific time would be better... but if with time is easyer at 7:00am would be nice
    If possible to add a shortcut key to run it would be fine also

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: daily send email Outlook with attach

    in outlook you can not assign a shortcut key to a macro, but you can assign a shortcut key to a tool bar button, so if you add a tool bar button for your macro, then you can use alt and whichever key is defined in the name of the toolbar button to activate the macro

    do you want to send 1 email 5 times, 5 emails at one time or one email to 5 people?

    if you want an automated macro, as outlook has no type of timer object, you can set a task item, then use the event of the task, to send your emails

    you need to specify more what you want to do
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2015
    Posts
    5

    Re: daily send email Outlook with attach

    Quote Originally Posted by westconn1 View Post
    do you want to send 1 email 5 times, 5 emails at one time or one email to 5 people?
    Hi...

    What i need is to send 5 difrent emails all of them with difrent attachment (they are on the desktop) to several difrent people with diferent subject and diferent text.

    Is 5 diferent email everyday but the text and subject are the same all the days execept one that includes de actual date on the subject.

    I hope that i could make my self clear :-p

    Many thanks for the help :-)

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: daily send email Outlook with attach

    you can try like this
    Code:
    Private Sub Application_Reminder(ByVal Item As Object)
    Dim m As MailItem, i As Integer, recips, files
    recips = Array("asdf@some.com", "qwerty@someother.com.de", "fred@gmail.com", "pete@hotmail.com", "jo@delivery.net")
    files = Array("attach.xls", "left.txt", "img12345.jpg", "today.pdf", "performance.log")
    
    If Item.subject = "autorun" Then
        For i = 0 To UBound(recips)
            Set m = CreateItem(olMailItem)
            m.To = recips(i)
            m.subject = ""
            m.Body = ""
            m.Attachments.Add createobject("wscript.shell").specialfolders("desktop") & "\" & files(i)
            'm.Send
            m.Display
        Next
        ' update reminder for next day, change time to suit
        Item.ReminderTime Date + 1 & " 8:00:00 AM"
        item.reminderset = true
    
        End If
    End Sub
    as i have no idea where you have a list of the recipients, i have listed them in an array, same for the files,, this data could be stored in an external file of some sort or some table, you will need to build strings for each of the subjects and body text, if you want the body formatted, you will need to use html code

    for this to run automatically create a taskitem with a reminder for next day at whatever time, with a subject to suit, i used "autorun". edit the code to match
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2015
    Posts
    5

    Re: daily send email Outlook with attach

    now i have to copy that 4 more time to make one for each email so the total of five emails right??

    Abou the email adress there are some of them that are in a group of adress... do i need to do something special about that??? or i just need to copy the name to the vba??

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: daily send email Outlook with attach

    now i have to copy that 4 more time to make one for each email so the total of five emails right??
    no it is a loop for 0 to 4 is 5 emails

    Abou the email adress there are some of them that are in a group of adress... do i need to do something special about that???
    nothing special, just have them in list of some sort, i used an array with hardcoded email addresses, but there a many choices
    Last edited by westconn1; Sep 2nd, 2015 at 04:46 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2015
    Posts
    5

    Re: daily send email Outlook with attach

    But the emails are for diferente people how will it send the diferent attach for the right adress?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: daily send email Outlook with attach

    how will it send the diferent attach for the right adress?
    look at the 3rd and 4th lines of the code, each email address would match the file list in the same order

    something extra may be needed for different subjects or body text, but i had no criteria to work with
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width