Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vba - How to send email in Outlook on behalf of a Delegate?

I'm writing a VBA script that will fire off emails to our customers. I've made similar systems before, but the difference here is that these emails will use a generic From field (so the recipient only sees our company's name and not the individual sending it). This is easy to do manually.

Currently, I'm playing around with the SendUsingAccount with generic examples. But I can't figure out how to use that code since it's not an actual account on this machine per se. I just have delegate access to it.

So, can someone show me how to send email on behalf of someone else using VBA?

(Alternatively, I do have the username and password to the account. So, if I need to log into that account to send the email, I can do that too)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check out the MailItem.SentOnBehalfOfName Property. You should have delegate access to the mailbox/profile on whose behalf you want to send.

Example:

Sub SendEmailOnBehalf()
  Dim msg As Outlook.MailItem

  Set msg = Outlook.CreateItem(olMailItem)
  With msg
    .SentOnBehalfOfName = "Jimmy's boss' name"
    .Subject = "Email from someone else"
    .Body = "Hello" & vbNewLine 
  End With
End Sub

The email would say From Jimmy Pena on behalf of Jimmy's Boss in the From: field.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...