Skip to content

Instantly share code, notes, and snippets.

@yakov116
Created March 7, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakov116/3d3a55792f23c1cc5bc1 to your computer and use it in GitHub Desktop.
Save yakov116/3d3a55792f23c1cc5bc1 to your computer and use it in GitHub Desktop.
Enter file contents herePublic Sub Check_ReceivedTime(newMail As Outlook.MailItem)
Dim obj As Object
Dim ReceivedHour As Integer
Dim newReply As MailItem
Dim msg As String
ReceivedHour = Hour(newMail.ReceivedTime)
'Only do anything if before Shabbos
If weekday(newMail.ReceivedTime) < 6 Then
If weekday(newMail.ReceivedTime) = 5 Then
msg = "Sorry I am not in the office, I will respond on Sunday morning. If its urgent please email yitzchok@tntexperts.com"
Else
If ReceivedHour <= 2 Or ReceivedHour >= 19 Then
msg = "Sorry I have have left the office alrady, I will respond tomorrow morning after 10:30 am."
ElseIf ReceivedHour >= 3 And ReceivedHour <= 1030 Then
msg = "Sorry I am not in the office, I will respond after 10:30 am or on Sunday after 11:am."
Else
Debug.Print "After 10:30, not Friday. Do not sent the automated reply."
End If
End If
End If
'End If
If Len(msg) > 0 Then
Set newReply = newMail.Reply
CreateMail newReply.To, msg
MsgBox(newReply.Recipients.Count & " " & newReply.Recipients(0)
End If
Set newReply = Nothing
End Sub
Private Sub CreateMail(ReplyAddress As String, msg As String)
Dim objMail As Outlook.MailItem
Set objMail = CreateItem(olMailItem)
With objMail
.To = ReplyAddress
.Body = msg
.Subject = "Please Note!"
.Display
' or
' .Send
End With
End Sub
@HaLeiVi
Copy link

HaLeiVi commented Mar 7, 2016

I can't seem to edit the code, but here is my addition/edition:

Public Sub Check_ReceivedTime(newMail As Outlook.MailItem)
 
Dim obj As Object
Dim ReceivedHour As Integer
Dim newReply As MailItem
Dim msg As String
 
 
ReceivedHour = Hour(newMail.ReceivedTime)
 
'Only do anything if before Shabbos
If weekday(newMail.ReceivedTime) < 6 Then
If weekday(newMail.ReceivedTime) = 5 Then
    msg = "Sorry I am not in the office, I will respond on Sunday morning. If its urgent please email yitzchok@tntexperts.com"
Else
    If ReceivedHour >= 19 Then
    msg = "Sorry I have have left the office alrady, I will respond tomorrow morning after 10:30 am."
    ElseIf ReceivedHour < 10 Or (ReceivedHour = 10 And Minute(newMail.ReceivedTime) < 30) Then
    msg = "Sorry I am not in the office, I will respond after 10:30 am or on Sunday after 11:am."
 
Else
 
    Debug.Print "After 10:30, not Friday. Do not sent the automated reply."
 
End If
End If
End If
'End If
 

    Set newReply = newMail.Reply
    Debug.Print "There are " & newReply.Recipients.Count " recipients."
If msg <> "" Then
    CreateMail newReply.Recipeients(0), msg
End If
 
 
Set newReply = Nothing
 
End Sub
 
 
Private Sub CreateMail(ReplyAddress As String, msg As String)
 
Dim objMail As Outlook.MailItem
 
Set objMail = CreateItem(olMailItem)
 
With objMail
    .Recipients.Add(ReplyAddress)
    .Body = msg
    .Subject = "Please Note!"
 
    .Display
    ' or
    ' .Send
 
End With
 
End Sub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment