I have a program that sends and email out to user when they have been added in.
I want the email to cc in multiple members of the IT team, however, I can only get it to CC to one person.
Below is my code:
objMail = CType(objOutlook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
' Set the properties of the email.
With objMail
.Subject = "Website Credentials"
.To = "chris.downs#test.com"
.CC = "benji#test.com, Alicia#test.com"
.Body = "Hi"
.Send()
End With
This causes the email not to send at all. I have also attempted the below and this only CC's the last person not both.
' Set the properties of the email.
With objMail
.Subject = "Website Credentials"
.To = "chris.downs#test.com"
.CC = "benji#test.com"
.CC = "Alicia#test.com"
.Body = "Hi"
.Send()
End With
Is there a simple way of doing this that I'm missing?
Outlook, unlike standard email clients, separates entries on the TO, CC, and BCC lines with ;, not ,. Change your CC line to
.CC = "benji#test.com; Alicia#test.com"
and it should send to both.
Your first try wasnt that bad.
Just replace the comma with a semicolon.
I think it should work like this
.CC = "benji#test.com; Alicia#test.com"
Related
I would like to reply to an email without including the original email, but include the sender as the recipient, the subject, and my signature.
Currently I have Set objDoc = ActiveInspector.WordEditor. I tried looking for the body of the email here, so I can replace it with other text.
I would like to retain the Subject of the email I am replying to, the Sender, and the Recipient.
Here is the code I have for my current reply:
With oReply
.BCC = bccField
.CC = ccField
.HTMLBody = "<HTML><Body><span>my reply here</span><Body></HTML>" & .HTMLBody & "<span>" & "Additional stuff" & "</span>"
End With
I tried taking out the .HTMLBody in between the <span>s, which does take out the original user's message but also takes out my signature.
Instead of using the reply functionality, just create a new mailItem and transfer the details over.
Example below uses the original email. So wherever you have Set oReply = (something).Reply you will replace or update that with Set originalMailItem = (Something). This (something) should be the original mail you are attempting to reply to.
In order to effectively insert the signature, we have to .Display the mailItem. Otherwise outlook will note generate the signature. Make sure the signature settings are correct on your outlook client to default to the desired signature for new mail items.
Set newMail = outApp.CreateItem(olMailItem) 'Create a new mail instead of replying to existing
With newMail
.Display
.HTMLBody = "<HTML><Body><span>my reply here</span><Body></HTML>" _
& "<span>" & "Additional stuff" & "</span>" _
& .HTMLBody 'HTMLBody already contains the signature once the email was displayed so we just tack it onto the end.
.To = originalMailItem.SenderEmailAddress
.CC = originalMailItem.CC
.BCC = originalMailItem.BCC
.Subject = originalMailItem.Subject
'.Send 'To send the reply
End With
I have the following code but the email that is created doesn't have any categories set. Ever.
Private Sub Application_Reminder(ByVal Item As Object)
.
.
.
Dim objMail As Outlook.mailItem
Set objMail = Application.CreateItem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.To = toContent
.CC = ccContent
.HTMLBody = messageContent
.Categories = Item.Categories
.Subject = Item.Subject
.Send
End With
.
.
.
End Sub
The Item object is a Task object that has a reminder set. I'm trapping the reminder in the Application_Reminder sub and generating an email from it. All properties get copied from the task to the email. At run time I can but a breakpoint on .Send and see that the .Categories property of the email is set correctly. When the email is received, that has been reset and is blank. The categories that I'm using are the standard Outlook ones.
To avoid releasing potentially private information on outgoing email messages, categories are not sent with email in Outlook when you use Exchange server mailboxes. When you use categories with internal codes or potentially embarrassing keywords, the recipient will not see them.
The Category is removed by Exchange Server's transport rules, not Outlook, when the message is sent. You may check out the item placed to the Sent Items folder.
If you need to send categories on outgoing email you can use the SendPersonalCategories registry entry.
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Preferences
DWORD: SendPersonalCategories
Value Data: 1 to keep categories on sent mail, 0 to not include categories
Where 16.0 stands for the Outlook version (2016).
Read more about that in the Sending Categories on Email Messages article.
I'm trying to use Word VBA to send a document to an email recipient. For the most part, it is not difficult. I have this code so far:
With oItem
'Set the recipient for the new email
.To = "person1#mail.com"
'Set the recipient for a copy
.CC = "ccperson#mail.com"
'Set the subject
.Subject = "Blah blah"
End With
My problem is that I have several sender email addresses configured in Outlook, and Outlook is picking the wrong one by default.
Is there a way to specify a sender email address using the method above? Needless to say, the intuitive code line for specifying a sender address (.From = me#wherever.com) does not work. Thank you.
UPDATE:
I finally got my code to work after modifying it using the suggestions from peakpeak and Dimitry below. My changes were
1) to include a reference to the Microsoft Outlook 16 object library so that I could get access to the Outlook.MailItem datatype. The mail would send fine with the code above (without the reference), but would always send with the wrong From address.
2) Declare the mail item as Outlook.MailItem. This seemed to enable the SentOnBehalfOfName field.
3) Used my desired From: email address in the SentOnBehalfOfName field.
Here is the working code:
Dim MAPIMailItem As Outlook.MailItem
Set MAPIMailItem = olkApp.CreateItem(olMailItem) 'Create a new mail message
With MAPIMailItem
.BodyFormat = olFormatPlain
.to = strTo
' SentOnBehalfOfName sets the From field on my machine,
' AFTER I declared MAPIMailItem as Outlook.MailItem
.SentOnBehalfOfName = "fromAddress#foo.com"
.Subject = strSubject
.body = strBody
.attachments.Add strAtt
'.send
.Display
End With
I use this code:
Dim WantedAccount as String ' Set to preferred account name
Set MAPISession = objOutlook.Application.Session 'Get the MAPI Outlook session
Set MAPIMailItem = objOutlook.CreateItem(olMailItem) 'Create a new mail message
With MAPIMailItem
For Each Account In MAPISession.Accounts
If Account = WantedAccount Then
.SendUsingAccount = Account
Exit For
End If
Next
If you are sending through an Exchange account, set the MailItem.SentOnBehalfOfName property (assuming you have the right to send on behalf of the specified mailbox). If you are sending through a POP3/SMTP account, set the MailItem.SendUsingAccount property.
I followed the below example.
https://www.slipstick.com/developer/create-a-new-message-using-vba/
I want to display address book name when automatically making the email draft.
For example, in this case,
I am able to display "BZ#gmail.com" in the address field but I want to display an address book's name "Business Team" because "Business Team" is easier to see.
Here is my code. it is almost same as the example code.
Public Sub CreateNewMessage()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.To = "Alias#domain.com"
.CC= "Alias2#domain.com"
.BCC = "Alias3#domain.com"
.Subject = "This is the subject"
.Categories = "Test"
.VotingOptions = "Yes;No;Maybe;"
.BodyFormat = olFormatPlain ' send plain text message
.Importance = olImportanceHigh
.Sensitivity = olConfidential
.Attachments.Add ("path-to-file.docx")
' Calculate a date using DateAdd or enter an explicit date
.ExpiryTime = DateAdd("m", 6, Now) '6 months from now
.DeferredDeliveryTime = #8/1/2012 6:00:00 PM#
.Display
End With
Set objMsg = Nothing
End Sub
I can send only by "alisas#domain.com" and when I see the opened draft, email address displayed.
How can I display address book name on draft?
For the first part of your question, refer to Recipients.Add Method (Outlook).
For CC's, you need to change the recipient type, see answer for this SO question.
I need to create a email, but when the button is triggered i want it to open Outlook with a preformatted email.
Since the client have some restictions, I do not want it to send the email from the program itself, I want it to open in outlook.
Something like this:
Dim email As New CDO.Message
With email
.From = "the_sender#company1.com"
.To = "the_reciever#company2.com"
.Subject = "Great e-mail"
.HTMLBody = "<h1>Header for a cool email</h1> And cool HTML"
.AddAttachment("Cute_kitty.jpg")
'.Send() NO! Open outlook with this stuff typed above and make sender useless
End With
How can i do this?
I found this stuff, but it does (of course) not support html-email and attachments...
Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process
proc.StartInfo.FileName = "mailto:the_reciever#company2.com?subject=Great e-mail&body=My cool email that does not support html n stuff"
proc.Start()
Suggestions?
If you want to open the message in Outlook, then you need to use the Outlook Object Model. Something along the lines:
set App = CreateObject("Outlook.Application")
set NS = App.GetNamespace("MAPI")
NS.Logon
set email = App.CreateItem(0)
With email
.To = "the_reciever#company2.com"
.Subject = "Great e-mail"
.HTMLBody = Your HTML text"
.Attachments.Add("c:\temp\Cute_kitty.jpg")
.Display
End With