0
votes

I currently want to build a VBA function that enables people to send emails using a group email address(e.g. person A has an email address [email protected] and he is also a member of "student" group and has access to send emails using the groups email address [email protected])

I am thinking about using a VBA to build such a function. It is easy to construct body, recipient and etc. but how to shift the sender i.e. from field to the group email address?

2

2 Answers

0
votes

Did you want any more than just how to send it? I'm slightly confused by your question.

Sub Mail_Workbook_1()
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it. Or pass variables to it
    With OutMail
        .To = "[email protected]" 'You can also set it equal to something like TextBox1.Text or any string variable or item
        .CC = ""
        .BCC = ""
        'Once again for the next two you can pull this from a cell, a textbox, or really anything
        .Subject = "This is the Subject line"
        .Body = "Hello World!" 
        .Attachments.Add ActiveWorkbook.FullName
        ' You can add other files by uncommenting the following line.
        '.Attachments.Add ("C:\test.txt")
        ' In place of the following statement, you can use ".Display" to
        ' display the mail.
        .Send   
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
0
votes

Maybe you just need to edit the reply-to address so that any replies get sent to the group?

Here's how, using Outlook:

'Tools > References ... > check "Microsoft Outlook object library"
Dim outlookApp As Outlook.Application
Dim mailMsg As MailItem
Dim replyToRecipient As Recipient

Set outlookApp = CreateObject("Outlook.Application")
Set mailMsg = outlookApp.CreateItem(olMailItem)

With mailMsg
    .To = "[email protected]" 
    Set replyToRecipient = .ReplyRecipients.Add("[email protected]") ' group adderss
    replyToRecipient.Resolve
    If Not replyToRecipient.Resolved Then Err.Raise 9999, , _
        replyToRecipient.Address _
        & " could not be resolved as a valid e-mail address."
    '...
    '... edit body etc. here...
    '...
    .Display
End With