Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 505439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:35:56+00:00 2026-05-13T06:35:56+00:00

I am writing a Bash shell script for Mac that sends an email notification

  • 0

I am writing a Bash shell script for Mac that sends an email notification by opening an automator application that sends email out with the default mail account in Mail.app. The automator application also attaches a text file that the script has written to. The problems with this solution are

  1. It is visible in the GUI when sending
  2. It steals focus if Mail is not the current application
  3. It is dependent on Mail.app’s account setup being valid in the future

I figure to get around those shortcomings I should send the mail directly from the script by entering SMTP settings, address to send to, etc. directly in the script. The catch is I would like to deploy this script on multiple computers (10.5 and 10.6) without enabling Postfix on the computer. Is it possible to do this in the script so it will run on a base Mac OS X install of 10.5. and 10.6?

Update: I’ve found the -bs option for Sendmail which seems to be what I need, but I’m at a loss of how to specify settings.

Also, to clarify, the reason I’d like to specify SMTP settings is that mails from localhost on port 25 sent out via Postfix would be blocked by most corporate firewalls, but if I specify the server and an alternate port I won’t run into that problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:35:56+00:00Added an answer on May 13, 2026 at 6:35 am

    Previously, this answer was based on the default inclusion of a recent Python on Mac OS X. Since then, the Python ecosystem has evolved and Python is not available on a clean install. This answer has been updated for modern systems, but is much more involved and exceeds the scope of the original poster’s request.

    Python and it’s built-in standard library provides some nice facilities for sending email if you’re willing to install it. Consider using the stock installer or installing homebrew followed by brew install python.

    From there, customize the following script based on stock examples to suit your needs.

    # Settings
    
    SMTP_SERVER = 'mail.myisp.com'
    SMTP_PORT = 25
    SMTP_USERNAME = 'myusername'
    SMTP_PASSWORD = '$uper$ecret'
    SMTP_FROM = 'sender@example.com'
    SMTP_TO = 'recipient@example.com'
    
    TEXT_FILENAME = '/script/output/my_attachment.txt'
    MESSAGE = """This is the message
    to be sent to the client.
    """
    
    # Now construct the message
    import pathlib
    import smtplib
    import email.message
    
    msg = email.message.EmailMessage()
    msg.set_content(MESSAGE)
    text_path = pathlib.Path(TEXT_FILENAME)
    msg.add_attachment(
        text_path.read_text(),
        maintype='text',
        subtype='plain',
        filename=text_path.name,
    )
    msg['From'] = SMTP_FROM
    msg['To'] = SMTP_TO
    # msg['Subject'] = SMTP_SUBJECT
    
    # Now send the message
    with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as mailer:
        mailer.login(SMTP_USERNAME, SMTP_PASSWORD)
        mailer.send_message(msg)
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 422k
  • Answers 422k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can have feature branches that yourself and the graphics… May 15, 2026 at 11:22 am
  • Editorial Team
    Editorial Team added an answer An oft forgotten fact is that operator[] will instantiate the… May 15, 2026 at 11:22 am
  • Editorial Team
    Editorial Team added an answer It's adding the new node to the head of the… May 15, 2026 at 11:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.