I have manually created a signature in outlook with name “Microsoft”.
I need to change Reply Signature to cited one.
I have installed Redemption and used the below code ,But I got Type Mismatch at this line Account.ReplySignature = "Microsoft"
Sub Change_Signature()
Dim Account As Variant
Dim Session As Object
Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
Set Account = Session.Accounts.GetOrder(2).Item(1) 'First mail account
Account.ReplySignature = "Microsoft"
Account.Save
End Sub
As always, Thanks for all help.
Please, try the next way:
Account.ReplySignature is an object! So, it must be set, it cannot be a string (Signature.name)...
In order to benefit of VBA Intellisense in the discussed case, I would like to suggest you to firstly set a reference to 'Redemption Outlook and MAPI Com library'. Since you try using Redemption you certainly registered the Com object...
Declare variables in a way to see what properties/methods do they expose:
Dim Account As RDOAccount, Session As RDOSession, Signature As RDOSignature
Use the next function able to return a session signature object by its name:
Function setSignature(strSign As String, Account As RDOAccount) As Redemption.RDOSignature
Dim Signature As RDOSignature
For Each Signature In Account.Session.Signatures
If Signature.Name = strSign Then
Set setSignature = Signature: Exit Function
End If
Next
End Function
Use the next adapted code:
Sub Change_Signature()
Dim Account As RDOAccount, Session As RDOSession, Signature As RDOSignature
Const signName As String = "IV_Signature"
Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
Set Account = Session.Accounts.GetOrder(2).Item(1) 'First mail account
Set Signature = setSignature(signName, Account)
If Account.ReplySignature Is Nothing Then
Set Account.ReplySignature = Signature
Account.Save: MsgBox "Changed to """ & signName & """!"
Else
If Signature.Name <> Account.ReplySignature.Name Then
Set Account.ReplySignature = Signature
Account.Save: MsgBox "Changed to """ & signName & """!"
Else
MsgBox "This account already usess signature """ & signName & """..."
End If
End If
End Sub
The above code can be adapted to use late binding, but you can only use it, without being able to see the rest of used objects properties, methods in case of future needs/developments... Then, early binding is always faster then late. In this very case this aspect does not matter too much, but it is good to have it in your mind, I think.
Of course, there are ways to improve it, for instance to determine if used signature name was misspelled... In such a case Signature will be Nothing, so If Signature is Nothing then MsgBox "Wrong signature string...": Exit Sub.
Related
In Outlook (2016 or 365), I would like to use VBA to create a rule that moves items I send to a specific person.
I've got most of the code done (lifted from a Microsoft code sample), but I can't figure out what the condition fields should get. I know it isn't right (there's no such thing as ".sender" in that type of object), but I don't know what I SHOULD put there. There are only seven properties on a ToOrFromRuleCondition (Application, Class, ConditionType, Enabled, Parent, Recipients, and Session), and none of them deal with the sender.
In the code below:
colRules, objRuleSend are Outlook.Rules objects
objToCondition is an Outlook.ToOrFromRuleCondition
RuleName is a string with only letters in it
Address is a string variable with a name.name#company.com format.
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Sender = Address ' <-- this is the line that fails.
.Recipients.ResolveAll
End With
You can intercept the Application.ItemSend event, check if the recipients are right, then set the MailItem.SaveSentMessageFolder property to the right folder.
This should work
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Recipients.Add Address ' <-- this is the line that is fixed.
.Recipients.ResolveAll
End With
Trying to set up a small task tracking workbook that will email our team once a cell gets filled in with "complete" (we use outlook). This is the code I have come up with so far, but I'm having trouble getting it to work
Private Sub Worksheet_Change(ByVal Target As Range)
Dim varActCell As Variant
Set varActCell = Range(ActiveCell).Offset(rowoffset:=0, columnoffset:=-1)
If Target.Column = 5 And InStr(varActCell, "Complete") Then MsgBox "Success"
call: Emailsub
End Sub
I attached a link to a similar thread with the email sub I'll use, but I'm having trouble activating it.
Can Excel send an email to different users based cell value?
you must omit those ":" between Call and Emailsubso that you have to write
Call Emailsub
but you can also simply type
Emailsub
finally should your Emailsub be as the sendMail of the link you provided then you're also missing passing arguments to your sub like, for instance:
sendMail strTo, strSubject, strBodyText 'where the arguments must all be of `String` type
while there also are two more Optional arguments, which means you can choose to omit whichever of them, like:
Emailsub strTo, strSubject, strBodyText, strCC, oAttachments
Emailsub strTo, strSubject, strBodyText, strCC
Emailsub strTo, strSubject, strBodyText, , oAttachments
if passed, these last two arguments are expected to be of String type and of Collection type.
But being Optional the Sub can work without you passing any value for them and thus assuming default values which are, respectively, a null string ("") and a void Collection
Edited to add a usage example
For example you may code like this:
strTo = "John#provider.com"
strSubject = "hoping it works"
strBodyText = "this is my very first attempt at using VBA and Outlook"
Emailsub strTo, strSubject, strBodyText
I want to organize messages in folders by domain (and possibly user). I have a script but it can't get the SMTP addresses from exchange users. The below code is an excerpt from the address extractor.
///For each obj in objFolder.Items
If obj.SenderEmailAddress = "EX" Then
Set objSender = obj.Sender
If Not (objSender Is Nothing) Then
Set objExchUser = Sender.GetExchangeUser()
If Not (objExchUser Is Nothing) Then
strSender = objExchUser.PrimarySmtpAddress
End If
End If
Else
If obj.SenderEmailAddress = "" Then
strSender = "ERROR#ERROR.GOV"
Else
MsgBox obj.SenderEmailAddress
'MsgBox obj.PrimarySmtpAddress 'errs out
'MsgBox Sender.GetExchangeUser() 'errs out
'MsgBox Obj.Sender.GetExchangeUser() 'errs out
strSender = obj.PrimarySmtpAddress
End If
End If
///Next
The code works but for those coming from an email group (helpdesk#myexchange.org for example) or spoofed email addresses.
obj.SenderEmailAddress results in "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (removedtextforstack)/CN=RECIPIENTS/CN=7E2removedtextforstackF6-USERNAME"
I believe this is to be expected, but Sender.GetExchangeUser() gives an Object Required error. I don't particularly want 3000 lines of code to dig through AD to try to look up an AD code/user for every email. We use office 365 and it's managed by many people, so things aren't straitforward with accessing the address lists.
MailItem.Sender.GetExchnageUser().ProimarySmtpAddress should work fine for the EX senders, but your code checks the SenderEmailAddress property instead of SenderEmailType. Change it to
If obj.SenderEmailType = "EX" Then
You can also check the PR_SENT_REPRESENTING_SMTP_ADDRESS property (DASL name http://schemas.microsoft.com/mapi/proptag/0x5D02001F, use MailItem.PropertyAccessor.GetProperty) before using the MailItem.Sender property (which is more expensive)
I have a work-around that seems decently efficient.
Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
a = Split(obj.PropertyAccessor.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS), vbCrLf)
For i = 0 To UBound(a)
If InStr(1, a(i), "From:", vbTextCompare) = 1 Then
MsgBox Replace(Split(a(i), "<")(1), ">", "")
End If
Next
This pulls the SMTP address directly from the header and does not care what type of message it is.
There still has to be a better way though...
I'm trying to automate the sending of an email through Lotus Notes 9.0 using VBA. The code will load up notes, which asks for my password but before the password prompt shows up, I get an error. The error I run in to is "Run-time error '-2147417851 (80010105)': Automation Error The server threw an exception" When I hit debug, the line that it fails on is "Set obDoc = obDB.CreateDocument". A lot of what I've seen online example wise matches what I'm doing in my code, so I'm not sure where the problem is.
Here's the code:
Sub Send_Emails()
Dim stSubject As Variant
Dim emailList As Variant
Dim obSess As Object
Dim obDB As Object
Dim obDoc As Object
'----Create Email List - separate function, dynamically creates email list based off report processing done in other functions
CreateEmailList
'----Info for Subject
stSubject = "test subject"
'----Create Notes Session
Set obSess = CreateObject("Notes.NotesSession")
Set obDB = obSess.GETDATABASE("", "")
If obDB.IsOpen = False Then
Call obDB.OPENMAIL
End If
'----Create the e-mail - **FAILURE OCCURS HERE**
Set obDoc = obDB.CreateDocument
'----Add values to the email
With obDoc
.form = "Memo"
.SendTo = "test#test.com"
.blindcopyTo = emailList
.Subject = stSubject
.HTMLBody = "<HTML><BODY><p>test</p></BODY></HTML>"
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, emailList
End With
'----Clean Up
Set obDoc = Nothing
Set obDB = Nothing
Set obSess = Nothing
MsgBox "The e-mail has been sent successfully", vbInformation
End Sub
You mention that you are using Notes 9, so I looked at the online help for Notes 9.01 and the help page for the OpenMail method says
Note: This method is supported in LotusScript® only. For COM, use OpenMailDatabase in NotesDbDirectory.
Now, you're actually using the OLE automation classes (rooted at Notes.NotesSession), not the COM classes (rooted at Lotus.NotesSession), so I don't know if you can use the NotesDbDirectory class or not, but the other way of opening the current user's mail database would be to call NotesSession.GetEnvironmentString("MailServer",true) and NotesSession.GetEnvironmentString("MailFile",true), and use those as the values for your call to GetDatabase.
I have the code to send an email through Lotus Notes 7. It works well. From what I've seen there are two methods of doing this, and only one of them requires that you specify a database. I'm using the method that doesn't require that, because multiple people will be using this code, and most of them don't know how to modify or read VB.
What I want to do is set the reply-to portion of the email. I have tried every variation I can think of, and nothing seems to work (different errors for different ways).
Thanks in advance,
Aaron.
Sub Email_Atrack_Report(SubjectLine As String, _
AgentOracle As String, TMAddress As String)
Dim NSession As Object
Dim NUIWorkSpace As Object
Dim NDoc As Object
Dim NUIdoc As Object
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set NDoc = NUIWorkSpace.ComposeDocument("", "", "Memo")
Set NUIdoc = NUIWorkSpace.CURRENTDOCUMENT
With NUIdoc
.FieldSetText "EnterSendTo", AgentOracle & "#Company.com"
.FieldSetText "EnterCopyTo", TMAddress
.FieldSetText "Subject", SubjectLine
.FieldSetText "Body", "**PASTE Atrack HERE**"
.GotoField ("Body")
.FINDSTRING "**PASTE Atrack HERE**"
Sheets("EmailOutput").Range("MessageBody").Copy
.Paste
.send
.Close
End With
Set NUIdoc = Nothing
Set NDoc = Nothing
Set NUIWorkSpace = Nothing
Set NSession = Nothing
End Sub
You can use the Principal field to specify an address that will show up as the "From" address. I don't believe there is a way to set this via NotesUIDocument, but you should be able to get the mail database using the NotesDatabase.OpenMail method.
Set session = CreateObject("Notes.NotesSession")
Set maildb = session.getDatabase("", "")
Call maildb.OpenMail
If Not maildb.IsOpen Then Call maildb.Open("", "")
Set maildoc = maildb.createdocument
Set body = maildoc.createrichtextitem("body")
Call body.AppendText( Sheets("EmailOutput").Range("MessageBody").Text )
Call maildoc.replaceitemvalue("form", "memo")
Call maildoc.replaceitemvalue("subject", subject)
Call maildoc.replaceitemvalue("principal", "reply-to-this-user")
Call maildoc.send(false,recipient)
There a two ways to solve this, building the document and use the send method, or copy the document to the mail.box.
A good way to start is to read this blog entry by Jake Howlett
These are the items that can be used in the email:
Principal
iNetFrom
DisplaySent
ErrorsTo
ReplyTo
CopyTo
BlindCopyTo
SendTo
You should just need to set the "ReplyTo" item on the document, as in:
.FieldSetText "ReplyTo", "address#company.com"