I have been using public folder and sending emails on outlook. Whenever we send emails with the public folder email address (e.g info#company.com), we will CC info#company.com. So that we will keep the email in our public folder.
I have created some VBA code to send outlook email automatically.
My question is: Is it possible to automatically categorize (e.g. customer-inquiry) the email in our public folder when I send the email without showing the category to recipient (as .
Sub outlookActivate1()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
With OutMail
.BCC = ""
.BodyFormat = olFormatHTML
.Categories = "customer-inquiry"
.ShowCategoriesDialog
.Save
.display
End With
On Error GoTo 0
Set OutMail = Nothing
Set oItem = Nothing
End Sub
No, it is not. You may consider adding a user property to the mail item instead. See UserProperties for more information.
Related
I am trying send several items at the same time.
I have two mail addresses in my Outlook. The first is a personal work mail (like j.doe#company.com) and second is a shared mail account (like support#company.com).
I tried:
Set objOutlook = CreateObject("Outlook.Application")
Set objMailMessage = objOutlook.CreateItem(0)
Dim oAccount As Outlook.account
Set oAccount = Session.accounts.Item(2)
objMailMessage.SendUsingAccount = oAccount
objMailMessage.display
I found this won't work with shared email accounts.
Most forums advise to use .SentOnBehalfOfName. When I try it on one email, the email has something like this in the Sender box j.doe#company.com - Sent on behalf of name: "support#company.com.
When I send mail from Outlook manually, it only shows the shared account on the received message. (It is not a big deal, but would be nicer if the code would work in the same style as manually.)
Also, when I put the code in a loop, half mails are sent with shared accounts and half with personal account.
And here is the code with .SentOnBehalfOfName which is going to be looped.
Set objOutlook = CreateObject("Outlook.Application")
Set objMailMessage = objOutlook.CreateItem(0)
With objMailMessage
.To = email
.Subject = msgSubj
.CC = ccp
.BCC = "support#company.com"
.SentOnBehalfOfName = "support#company.com"
.HTMLBody = msgText & "<br>" & "<br>" & msgSign
.Attachments.Add path
If rev > 0 Then
.Save
Else
.Send
End If
End With
This code attempts to ensure the .SentOnBehalfOf is consistent.
Option Explicit
Sub sendFromOtherMailbox()
' Code in Outlook, not called from another application
Dim objMailMessage As mailItem
Dim uMailbox As recipient
' Should not be necessary but this is used later to ensure
' the entry in .SentOnBehalfOfName is what you think it is.
Set uMailbox = Session.CreateRecipient("Preferably display name here rather than email address.")
uMailbox.Resolve
' An email address always resolves so the "If Resolved" test is not useful
' if an email address was used in .CreateRecipient
If uMailbox.Resolved Then
Set objMailMessage = CreateItem(olMailItem)
With objMailMessage
.Subject = "send From Other Mailbox"
.SentOnBehalfOfName = uMailbox
.Display
End With
End If
End Sub
The following code is the code for sending Outlook mail:
Sub SendEmail()
Dim OutlookApp As Object
Dim MItem As Object
Set OutlookApp = CreateObject("Outlook.Application")
Dim Sendrng As Range
Set Sendrng = Worksheets("Test").Range("A1").SpecialCells(xlCellTypeVisible)
Sendrng.Copy
Set MItem = OutlookApp.CreateItem(0)
With MItem
.To = "test#email.com"
.Subject = "Test"
.Display
Threading.Thread.Sleep(2000)
End With
End Sub
How can I check if the Outlook mail item is active?
I am looking for a code like this:
.Display
Threading.Thread.Sleep(2000)
If MItem is not active then
exit sub
End if
In other words, display is still displaying?
Because I don`t want the users to close the opened Outlook mail screen.
So essentially you want to find out when the message is closed? Call Display specifying TRUE as the parameter (it defaults to false if not specified) - that will cause Display to be modal. The line .Display needs to be changed to .Display(true)
I have an Excel spreadsheet Auditing Vendor documentation with expiry dates.
I have created an VBA macro which when I choose (Ctrl + M) will send an email requesting updates for specific documents based on the expiry dates.
Everything is beautiful and works like a charm.
My question is how do I include an Outlook Signature at the end of the email?
I would like it to pick up based on whoever has the spreadsheet open so that if Charlie Brown wants to trigger an email it would include Charlie Brown's Signature at the end.
It already auto-fills Charlie Brown as the Sender so I should be able to do this.
Any suggestions?
Here is an Example
Option Explicit
Sub AddSignature()
Dim olApp As Object
Dim olMail As Object
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
With olMail
.Display olMail.HTMLbody '<- adding default signature
End With
With olMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.HTMLbody = "Hello." & "<br>" & .HTMLbody '<- adding default signature
.Display
' .Send
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub
also see Insert Signature in mail From Ron de Bruin
If you use excel to grab the new mail item signature you will get a flag for suspicious activity that the user could acknowledge
Dim OApp, OMail As Object
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
Dim sig As String
sig = OMail.HTMLbody
If you know the name of the signature you can go browse for it
Dir (CStr(Environ$("userprofile")) & "\appdata\roaming\microsoft\signatures\")
I currently want to build a VBA function that enables people to send emails using a group email address(e.g. person A has an email address a#111.com and he is also a member of "student" group and has access to send emails using the groups email address student#111.com)
I am thinking about using a VBA to build such a function. It is easy to construct body, recipient and etc. but how to shift the sender i.e. from field to the group email address?
Did you want any more than just how to send it? I'm slightly confused by your question.
Sub Mail_Workbook_1()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
' Change the mail address and subject in the macro before you run it. Or pass variables to it
With OutMail
.To = "tom#google.com" 'You can also set it equal to something like TextBox1.Text or any string variable or item
.CC = ""
.BCC = ""
'Once again for the next two you can pull this from a cell, a textbox, or really anything
.Subject = "This is the Subject line"
.Body = "Hello World!"
.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\test.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Maybe you just need to edit the reply-to address so that any replies get sent to the group?
Here's how, using Outlook:
'Tools > References ... > check "Microsoft Outlook object library"
Dim outlookApp As Outlook.Application
Dim mailMsg As MailItem
Dim replyToRecipient As Recipient
Set outlookApp = CreateObject("Outlook.Application")
Set mailMsg = outlookApp.CreateItem(olMailItem)
With mailMsg
.To = "abc#111.com"
Set replyToRecipient = .ReplyRecipients.Add("group#111.com") ' group adderss
replyToRecipient.Resolve
If Not replyToRecipient.Resolved Then Err.Raise 9999, , _
replyToRecipient.Address _
& " could not be resolved as a valid e-mail address."
'...
'... edit body etc. here...
'...
.Display
End With
My code displays a message with basic subject, body, attachment. Next the user manually updates and customizes the message and should send it. I want to record when (if) the email is sent. Is this possible or any tips?
My environment is Office 2007 with an excel based macro going to Outlook.
[Excerpt]
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = Email '.CC =
.Subject = Subj
.BodyFormat = olFormatHTML
.Body = Msg '.HTMLBody = Msg
If Not FileAttach = vbNullString Then .Attachments.Add (FileAttach)
.Display
End With
This is entirely possible, using the _Send event in the Outlook.MailItem class.
The way I use it, I create a class called EMail Watcher, so when I create the email and do the .Display, I then create a new EMailWatcher object and tell it to watch that email for send, then report back when it happens.
Here's the class as I use it. Basically, I also optionally can set the BoolRange so that if the user sends the email, that Excel range gets updated with True. I can also have the class update an Excel range with the time the email is sent.
Public BoolRange As Range
Public DateRange As Range
Public WithEvents TheMail As Outlook.MailItem
Private Sub TheMail_Send(Cancel As Boolean)
If Not BoolRange Is Nothing Then
BoolRange.Value = True
End If
If Not DateRange Is Nothing Then
DateRange.Value = Now()
End If
End Sub
And here's how I use it:
With oMail
.To = addr
.Subject = "CCAT eVSM Utilities License Code"
.Body = "Message body"
.Display
End With
Set CurrWatcher = New EmailWatcher
Set CurrWatcher.BoolRange = Range("G12")
Set CurrWatcher.TheMail = oMail
Hopefully that helps...