Always Send from Default Account, depend of receive account

Status
Not open for further replies.

Zlatko

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hello,
I have one problem with script "send from default address", because i need to omit this rule for gmail account.

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount = "Account Name" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub

Regards
Zlatko
 

Zlatko

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Thank you Diane, but it not working..
This is example of code for "Always reply from default address":

Public Sub New_Reply()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem

For Each oAccount In Application.Session.Accounts

If oAccount = "default_address@xxx.com" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next

End Sub

I created a new button with this function, but i want to exclude default reply when I reply from gmail received mails.

Regards
Zlatko
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This seems to work ok - it checks the recipient addresses for the gmail address and replies, otherwise it sets the sending account.

Code:
Public Sub AccountSelection()
Dim oAccount As Outlook.Account
Dim objMsg As MailItem, oMail As MailItem
   
If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
Set objMsg = ActiveExplorer.Selection.Item(1)
  
For Each Recipient In objMsg.Recipients
strRecip = Recipient.Address & ";" & strRecip
Next Recipient
 
If InStr(strRecip, "me@gmail.com") = 1 Then
Set oMail = objMsg.Reply
   oMail.Display
Else
For Each oAccount In Application.Session.accounts
   If oAccount = "me@slipstick.com" Then
  Set oMail = objMsg.Reply
  oMail.SendUsingAccount = oAccount
     oMail.Display
   End If
Next

End If
End If
Set objMsg = Nothing
End Sub
if you want ot capture the reply/replyall buttons, see http://www.slipstick.com/outlook/using-gmail-master-account-reply-using-correct-account/ for the method.
[DOUBLEPOST=1428989479][/DOUBLEPOST]BTW, that code won't work if you are bcc'd on the gmail address. The gmail address needs to be in the to or cc field.
 

Zlatko

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Thank you again Diane, code is ok but script is too slow for work...need 1 min to create new mail...
Whether there is an option to speed up work? That verifies only "TO" field of received mail...

Regards
Zlatko
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
How many addresses are the messages sent to? It shouldn't take that long to check the names and create a new message - it stops when it finds a match. Oops... it doesn't stop. Try adding Exit Sub after oMail.display.
[DOUBLEPOST=1429548894][/DOUBLEPOST]Also, try changing this
InStr(strRecip, "me@gmail.com") = 1

to
InStr(strRecip, "me@gmail.com") > 0
 

Zlatko

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Dear Diane,
It's better now...but it's still take too long for create mail, about 15-20 sec.
When I reply on not-gmail message, it take about 3-5 sec for create mail.
I add "Exit Sub" and change in line "InStr( )" > 0...
Scanned messages are sent only to one recipient,

Regards
Zlatko
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Try removing
For Each Recipient In objMsg.Recipients
strRecip = Recipient.Address & ";" & strRecip
Next Recipient

change
If InStr(strRecip, "me@gmail.com") > 0 Then

to

If InStr(objMsg.To, "me@gmail.com") >0 Then

I really don't think it's going to get too much faster though.
 
Status
Not open for further replies.
Top