I've modified an outlook message form to include a custom dropdownlist. I need to append the selected value from the dropdownlist onto the beginning and end of the message text when the user sends. How do I do this?
Example: User selects "Priority 1" from ddl and sends message "Here is a message." I would want the recipient to see "Priority 1 Here is a message. Priority 1" Thanks!
How are you sending the message throught the send function of the form you used or are you sending the form throught code i would recomend sending the form throught code this is because you have greater control over the features of the message being sent.
Combining this with the outlook and system variables you can return a fair amount of relevant and usful data.
Set DropBox = objPage.Controls("DropBoxName")
With oOMail
.To = "mail#adressee.com.au"
.Subject = DropBox.Text && "Subject"
.Body = "message" && DropBox.Text && vbCrLf
.Send
End With
Related
I'd like to program Outlook to send an email in advance, and, if no reply is sent to the target email by x date, send another email.
I've attempted experimentation, dabbling into Excel VBAs, but haven't found a solution.
I'm really quite unsure of how to do this, though I do have programming experience.
I'd like to program Outlook to send an email in advance
That is a very straightforward task. A lot of samples are available over the internet, for example, sample code in VB.NET:
Private Sub CreateSendItem(OutlookApp As Outlook._Application)
Dim mail As Outlook.MailItem = Nothing
Dim mailRecipients As Outlook.Recipients = Nothing
Dim mailRecipient As Outlook.Recipient = Nothing
Try
mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
mail.Subject = "A programatically generated e-mail"
mailRecipients = mail.Recipients
mailRecipient = mailRecipients.Add("Eugene Astafiev")
mailRecipient.Resolve()
If (mailRecipient.Resolved) Then
mail.Send()
Else
System.Windows.Forms.MessageBox.Show(
"There is no such record in your address book.")
End If
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message,
"An exception is occured in the code of add-in.")
Finally
If Not IsNothing(mailRecipient) Then Marshal.ReleaseComObject(mailRecipient)
If Not IsNothing(mailRecipients) Then Marshal.ReleaseComObject(mailRecipients)
If Not IsNothing(mail) Then Marshal.ReleaseComObject(mail)
End Try
End Sub
Read more about that in the following articles:
How To: Create and send an Outlook message programmatically
How To: Fill TO,CC and BCC fields in Outlook programmatically
How to create and show a new Outlook mail item programmatically: C#, VB.NET
if no reply is sent to the target email by x date, send another email.
You can set the following properties on the email:
MailItem.TaskDueDate which sets a Date value that represents the due date of the task for this MailItem.
MailItem.ReminderSet which sets a Boolean value that is True if a reminder has been set for this item.
MailItem.ReminderTime which sets a Date indicating the date and time at which the reminder should occur for the specified item.
In the Application.Reminder event handler you may check whether the mail item was replied or forwarded by reading a low-level property value. The property you would read would be PR_LAST_VERB_EXECUTED (0x10810003). Values are listed below:
EXCHIVERB_REPLYTOSENDER = 102
EXCHIVERB_REPLYTOALL = 103
EXCHIVERB_FORWARD = 104
Please remember that you can use the PropertyAccessor for that:
lastVerbExecuted = mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003")
I'm looking to forward email that I receive in Outlook to a new address with no changes - an exact clone, no envelope information nor signature added.
The email will always have an HTML table in the body and needs to be preserved identically. I can get it to forward but it always adds a blank email body with a signature "above" the original email, and then there is the standard From: and To: and email attributes above the original email.
Is there a way to remove this? I have tried to change this to generate a "new" object, as the new object is not bringing in the HTML body before forwarding.
Sub Send_Forward(ByRef oMail As Object, repBodyStr As String, sendMail As
Boolean)
Dim myForward As Object
Set myForward = oMail.Forward
myForward.Subject = myForward.Subject
myForward.HTMLBody = repBodyStr & "<br>" & myForward.HTMLBody
myForward.Recipients.Add "xxx#xxx.net"
myForward.Display
ExitSub:
Set myForward = Nothing
End Sub
Create a new item (Application.CreateItem), then just copy the HTMLBody property from the existing message and add the recipients.
UPDATE: if you need to copy the attachments (such as images), you would have to save the attachments from the original message (Attachment.SaveAsFile), then add them as attachments to the new message (MailItem.Attachments.Add). Note that this will not work with embedded OLE objects (in case of the RTF format) and embedded message attachments. For the images, you would also need to copy the PR_ATTACH_CONTENT_ID MAPI property using Attachment.PropertyAccessor.
Also note MailItem.Copy would not work as the message sent state will be copied (which his not what you want).
If using Redemption (I am its author) is an option, it allows to make a copy of the message without copying its sent state. Something like the following should do the job (off the top of my head):
Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set originalMsg = Session.GetRDOObjectFromOutlookObject(Application.ActiveExplorer.Selection(1))
set newMsg = Session.GetDefaultFolder(olFolderDrafts).Items.Add
'copy the message and clear out recipients
originalMsg.CopyTo(newMsg)
newMsg.Recipients.Clear
newMsg.Recipients.Add "xxx#xxx.net"
newMsg.Save
'now reopen the message in OOM and diplay it. Or you can use newMsg.Display
set myForward = Application.Session.GetItemFromID(newMsg.EntryID)
myForward.Display
I have an access form that runs a query. There is a command button on the form that I want to send an email with the query results attached in an excel spreadsheet. Using the code below I am able to attach the results and send the email ok. I would like to be able to format the email body so that it is more noticeable. I'm not really sure how to go about doing this and still have my query attached. I have also created an email template that I would use but I haven't been able to figure out how to use the template and attach the query results. I'm open for any suggestions. Any help would be greatly appreciated.
DoCmd.SendObject acQuery, "BoxOrder", "ExcelWorkbook(*.xlsx)", "me#home.com", _
"John#hishome.com", "", "BOX ORDER", _
"ALL BOXES STITCHED" & vbCrLf & "Questions: Please Call Me" & _
vbCrLf & "555-555-5555 x 66654", True, True
You could follow the Article from MS.
A proportion of the code is as follows:
Set ola1 = New Outlook.Application
Set mai1 = ola1.CreateItem(olMailItem)
mai1.To = strTo
mai1.Subject = strSubj
If bolHTML = True Then
mai1.HTMLBody = strBody
Else
mai1.Body = strBody
End If
mai1.Display
If you use the HTML (set bolHTML = True) version you can either have an RTF control on a Form and pass the formatted text over or hardcode your HTML with the formatting you need. Just set the "strBody" to the message you want.
Then you need to look into the Attachments.Add (MS Article) if you want to use the above code with your original purpose.
There's a full 599CD Email Seminar you could follow if you're going to be doing a lot with Email in Access.
My overall goal is to change the "From" sender on an incoming email to something else. Specifically, I get chat logs from Zopim chat and they're all coming from Zopim's "no-reply" email. However, I want these chat logs to be associated with in my CRM and thus I want them associated to people who we chat with.
I've created this VBA script, it runs without errors, however, no change is done to the incoming email. What am I doing wrong?
Option Explicit
Sub ZopimChatMessageRule(Item As Outlook.MailItem)
Dim body As String
Dim sndr As String
On Error GoTo Finally
body = Trim(Right(Item.body, Len(Item.body) - (InStrRev(Item.body, "EMAIL") + 5)))
sndr = Trim(Left(body, InStr(body, vbCrLf) - 1))
Item.sender.Address = sndr
Item.sender.Name = sndr
Item.sender.Update
Item.Recipients.ResolveAll
Item.Save
Finally:
End Sub
Your code is updating the name and address of a one-off address entry that does not exist anywhere. What you need to do is change the Sender and SentOnBehalfOf properties, which are read-only in the Outlook Object Model.
You can use MailItem.PropertyAccessor.SetProperty to update dozen or so PR_SENDER_xyz and PR_SENT_REPRESENTING_xyz MAPI properties - take a look at a message with OutlookSpy (I am its author - click IMessage button). Keep in mind that SetProperty will prevent you from modifying some properties Outlook considers "special".
If using Redemption is an option (I am also its author), you can set the Sender and SentOnBehalfOf properties directly:
set rSession = CreateObject("Redemption.RDOSession")
rSession.MAPIOBJECT = Application.Session.MAPIOBJECT
set Msg = rSession.GetRDOObjectFromOutlookObject(Item )
strEntryID = rSession.AddressBook.CreateOneOffEntryID("Fake User", "SMTP", "someuser#fake.domain.com", false, true)
set addressEntry = rSession.AddressBook.GetAddressEntryFromID(strEntryID)
Msg.Sender = addressEntry
Msg.SentOnBehalfOf = addressEntry
Msg.Save
I am writing an outlook sub procedure that takes the currently selected email, parses it, and creates a new email message. The parsing is simple enough: Extract the email addresses from the first line of the message and then the rest of the body is the regular email body in the new message.
I am using this basic code for setting the body of the new message:
Set newMsg = Outlook.Application.CreateItem(olMailItem)
With newMsg
.BodyFormat = olFormatHTML
.Body = newBody
'... set subject,etc
.Display
The problem is that the new message that is created loses all of the HTML formatting that the message I was copying the information from possessed ( and various font stylings). I tried setting the new message's body format to HTML (see code above), but that did not do the trick. Currently, the new message contains all of the textual data, but instead of the table, each cell's data is tab-delimited and the entire message body is in the same font.
BodyFormat does not behave as expected. Instead, HTMLBody can be used as below to properly display the body in HTML format:
With newMsg
.HTMLBody = newBody
'... set subject,etc
.Display