MS Access Redemption remove "person send on behalf of" - vba

When trying to send emails using another inbox, I change .SentOnBehalfOfName to the email I want to send from.
But then the email arrives with "MyRealName on behalf of EmailAddressIWantToSendFrom".
How do I remove MyRealName?
EDIT:
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_msg_file)
...
pretend that this comment is a bunch of code that modifies the body of MyItem, mostly doing text replacements in MyItem.HTMLBody
...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
safeItem.To = "person I want to send to"
safeItem.SentOnBehalfOfName = "desired address I want to sent from"
safeItem.Recipients.ResolveAll
safeItem.Send

To be able to send as that user, you need to have both send-as and receive-as rights. You'd need to connect to that user's mailbox and create the new message in the mailbox of the user you are trying to send as.
EDIT:
Try something like the following:
set rSession = CreateObject("Redemption.RDOSession")
rSession.MAPIOBJECT = Application.Session.MAPIOBJECT
set Store= rSession.GetSharedMailbox("some GAL name")
set Folder = Store.GetDefaultFolder(olFolderOutbox)
set Msg = Folder.Items.Add
Msg.Subejct = "test"
Msg.To = "user#domain.demo"
Msg.Send

Related

How to forward a calendar item without notifying organizer

I want to forward all calendar items within a certain date range to a specific email address without notifying the organizer.
Is there a way to do this using VBA code? I have the below code to not notify the meeting organizer but need to modify to forward all calendar items to a specific email address?
Also note I cannot forward as icalendar. I have a script which forwards emails when moved to a specific folder, however i cannot seem to convert or move meeting invites into the normal inbox folder.
Sub ForwardMeetingInvitation()
Dim olSel As Selection
Dim olMeeting As MeetingItem
Dim olFWMeeting As MeetingItem
Dim Recip As String
Set olSel = Outlook.Application.ActiveExplorer.Selection
Set olMeeting = olSel.Item(1)
'Replace with your own desired recipient's email address
Recip = "pirate#fakemail.com"
Set olFWMeeting = olMeeting.Forward
With olFWMeeting
.Recipients.Add (Recip)
.Attachments.Add olMeeting
.Display
End With
Set olSel = Nothing
Set olMeeting = Nothing
Set olFWMeeting = Nothing
End Sub

How to set Outlook From email address from Word VBA

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.

QTP, send mailer address

I am sending an email using the QTP outlook object model.
Here is the piece of code.
'Create an object of type Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.CreateItem(0)
'Set the email properties
myMail.To = "some_mail_id#gmail.com"
myMail.CC = "some_mail_id_2#gmail.com; some_other_mail#yahoo.com" 'Sending mails to multiple ids
myMail.BCC = "" 'If BCC is not required, then this line can be omitted
myMail.Subject = "Sending mail from MS Outlook using QTP"
myMail.Body= "Test Mail Contents"
myMail.Attachments.Add("D:\Attachment.txt") 'Path of the file to be attached
'Send the mail
myMail.Send
Now I needed to retrieve the sender email address & store it in an environment variable. myMail.Sender or myMail.sendermailaddres both of them are not working me.
The following code will give you the first email address the user you're connected to Outlook has access to:
objOutlook.Session.Accounts.Item(0)
I use a loop to find the account I want to send from like this:
iAccount = 0
For iLoop = 1 To oOutlook.Session.Accounts.Count
If UCase(Trim(oOutlook.Session.Accounts.Item(iLoop))) = UCase(Trim(EmailData("SendFrom"))) Then
iAccount = iLoop
Exit For
End If
Next
where EmailData is a Dictionary object containing the items I'm using for the mail item. When creating the mail item I use Set oMailItem.SendUsingAccount = oOutlook.Session.Accounts.Item(iAccount) to specify the account it should be sent from.

Change account settings in Outlook 2010 using VBA

I have a large number of forwarding email addresses which are all set to forward to the same email account. I find this is useful because if a business is hacked and my email address is stolen then I only have the change the email address for that business. For example, "amazon#mydomain.com", "ebay#mydomain.com" and "facebook#mydomain.com" would all be forwarded to "mailbox#mydomain.com".
When I want to send an email to the business, I have to go into Outlook and change the account set up to have the forwarding email address as the email address. I find this a nuisance. I know I can change who the email is from when I write it, but then the recipient sees "J Smith on behalf of newaddress#mydomain.com". I would rather it just showed the address I am using in the from field, as it does if I go into the account set up and change the email address there.
It would be nice to have a macro set up which asked me which email address I wanted to use and then sent the email for me. I have looked up how to change email account details in VBA, but it looks as if the details are all read-only. Is there a way to change my "from" email address cleanly? Or even setting up a new email account in VBA and deleting it immediately after sending it?
Try creating a userform with a combobox and a button on it. Load all your available accounts into the combobox to be able to select from it:
Private Sub UserForm_Initialize()
Dim acc As Account
For Each acc In ThisOutlookSession.Session.Accounts
Me.ComboBox1.AddItem acc.UserName
Next acc
End Sub
Then add some code to the button that selects the proper account:
Dim objApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set objApp = ThisOutlookSession.Application
Set objMail = objApp.CreateItem(olMailItem)
With objMail
.To = "lala#lala.com"
.CC = ""
.BCC = ""
.Subject = "Test"
.Body = "Test"
Dim i As Integer
For i = 1 To ThisOutlookSession.Session.Accounts.Count Step 1
If ThisOutlookSession.Session.Accounts.Item(i).UserName = Me.ComboBox1.Value Then
.SendUsingAccount = ThisOutlookSession.Session.Accounts.Item(i)
End If
Next i
.Display
End With
Maybe there is an event that is called when you are creating a new email, otherwise you have to add a button or something to bring the form up.
I had this exact same problem and ended up being able to solve it by installing Outlook Redemption and using the following script...
' Redemption code below. Must install Redemption to work.
' http://www.dimastr.com/redemption/faq.htm#14
Dim sItem, Tag
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = oMailItem
Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "From")
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = GetHashedReply(oMailItem)
Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "Sender")
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = GetHashedReply(oMailItem)
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that something has changed
sItem.Save
...where oMailItem is a normal Outlook MailItem that you can get with CreateItem() or get passed to you in the ItemSend() parameters.

Open mail client with pre formatted data

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