+ Reply to Thread
Results 1 to 3 of 3

Sending an automated Email thru a specific Email Server with different "from" address.

  1. #1
    Registered User
    Join Date
    02-01-2022
    Location
    Sarasota, FL
    MS-Off Ver
    Office 365
    Posts
    5

    Sending an automated Email thru a specific Email Server with different "from" address.

    I have successfully found and altered some VBA that automatically sends and email to employees, from a spreadsheet, when it is determined their weekly hours don't meet the requirement. Currently it sends from my corporate outlook account. this email is 100% internal use. I would like to have the email sent so that it shows a "dummy" email in the from. We know this is possible, if I send it thru a specific server here in the office. Ideally i want the email to show it is from something like "timecheckatcompany.com" So my question is, how do I route thru a specific server and show the "dummy" email? What little i've found seems to be VBA from within Outlook itself, and in this case I am initiating from excel.

    This is my code:
    Sub SendAllMail()
    'Setting up the Excel variables.
    Dim olApp As Object
    Dim olMailItm As Object
    Dim iCounter As Integer
    Dim Dest As Variant
    Dim SDest As String
    Dim xMailBody As String
    Dim DateWindow As String
    Dim dtToday As Date
    Dim StartDate As Date
    Dim EndDate As Date
    Dim ReqHour As String
    Dim objOutlookMsg As String


    Worksheets("Team Lists").Activate
    dtToday = Date
    StartDate = Cells(1, "H").Value ' this is the date the tick hours start evaluation from
    EndDate = Cells(1, "K") 'this is the end of the time period. 28 days is exactly 4 weeks. Alter the number 28 as appropriate if end date isnot correct
    'DateWindow = StartDate & " to " & EndDate
    'MsgBox (DateWindow)
    'Create the Outlook application and the empty email.
    ReqHour = Cells(1, "E")
    Set olApp = CreateObject("Outlook.Application")
    Set olMailItm = olApp.CreateItem(0)
    xMailBody = "Hi there," & vbNewLine & vbNewLine & _
    "It appears you have not logged enough hours this time Period."
    'Using the email, add multiple recipients, using a list of addresses in column A.
    With olMailItm
    SDest = ""
    For iCounter = 1 To WorksheetFunction.CountA(Columns(1))
    If SDest = "" Then
    SDest = Cells(iCounter, 1).Value
    Else
    SDest = SDest & ";" & Cells(iCounter, 1).Value
    'MsgBox (SDest)
    End If
    Next iCounter

    'Do additional formatting on the BCC and Subject lines, add the body text from the spreadsheet, and send.
    .BCC = SDest
    .Subject = " Review Needed!"
    .Body = xMailBody
    .Send
    End With

    'Clean up the Outlook application.
    Set olMailItm = Nothing
    Set olApp = Nothing
    End Sub

    It needs to go thrue MailServer Port 25 and the name of the server is data007.companyname.local

  2. #2
    Registered User
    Join Date
    08-24-2022
    Location
    hugo
    MS-Off Ver
    13
    Posts
    40

    Re: Sending an automated Email thru a specific Email Server with different "from" address.

    I have not tested this code:
    To send the email using a specific server and show the "dummy" email in the "From" field, you will need to modify the code to include the necessary details.

    Here is how you can do that:

    Add the following code before the Set olMailItm = olApp.CreateItem(0) line:
    Please Login or Register  to view this content.
    Change the .BCC line to set the recipients to the desired email addresses:
    Please Login or Register  to view this content.
    Save and run the code.
    After making these changes, the email should be sent from the specified server and the "From" field should show the "dummy" email address. You can further test and refine the code to ensure it works as expected.

  3. #3
    Registered User
    Join Date
    02-01-2022
    Location
    Sarasota, FL
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Sending an automated Email thru a specific Email Server with different "from" address.

    Thanks for this suggested code. I have added it to my code, and at the first line:
    olMailItm.MailServer = "data007.companyname.local" I am triggering the debugger.

    I am gettting:
    Run-Time error '438":
    Object doesn't support this property or method.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sending automated email and want to format specific word in email to colour font
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2021, 11:23 AM
  2. Email used range on different sheet, use lookup to populate "to" email address
    By carlito2002wgn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2019, 01:27 PM
  3. [SOLVED] vba email send from excel - ignore second email address if "ENTER EMAIL ADDRESS"
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2016, 07:22 AM
  4. Changing "From" Email address based upon "To"
    By Muhammad Atif Gul in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 03-20-2014, 02:57 AM
  5. Email workbook to email address in cell "a1" macro
    By klawlor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 09:20 AM
  6. Adding commas "," in email addresses for sending BULK Email stored cellwise..!
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2011, 09:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1