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 8147005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:12:08+00:00 2026-06-06T14:12:08+00:00

The following contents are in a file.i use a shell script to call a

  • 0

The following contents are in a file.i use a shell script to call a python script.This python script send the mail.But in the mail contents i see the output as shown below.Its all in oneline..What am i doing wrong

 /usr/bin/python $DIR/sm.py "$message"  "`cat /tmp/alert.txt`"

Input:The following are the contents of alert.txt

  Thu Jun 28 14:29:26 IST 2012

  Disk usage limit exceeded -Current disk usage is 167G-Configured disk usage is 200HTTPD connections exceeded configured usage limit -Current HTTPD connections is 21-Configured HTTPD connection is 20


  ========================OTHER INFO==================
  Total fds: 8
  Socket fds: 0
  Other fds: 8
  Free memory :Free Memory:183732
  Buffered memory Buffered Memory:78224
  Cache memory : Cache Memory:579040
  Disk usage is 167G
  DB connections 1
  Network connections 21
  CPU Usage: 0.0

Output:

  Thu Jun 28 14:29:26 IST 2012 Disk usage limit exceeded -Current disk usage is 167G-Configured disk usage is 200HTTPD connections exceeded configured usage limit -Current HTTPD connections is 21-Configured HTTPD connection is 20 ========================OTHER INFO================== Total fds: 8 Socket fds: 0 Other fds: 8 Free memory :Free Memory:183732 Buffered memory Buffered Memory:78224 Cache memory : Cache Memory:579040 Disk usage is 167G DB connections 1 Network connections 21 CPU Usage: 0.0

This is sm.py

import logging
import smtplib
import sys
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart


      try:
         smaid = qs[0].id
         gmailUser = 'no-reply@xxxxxxxxxxx.com'
         gmailPassword = '12345'
         mailServer = smtplib.SMTP('smtp.gmail.com', 587)
         mailServer.ehlo()
         mailServer.starttls()
         mailServer.ehlo()
         mailServer.login(gmailUser, gmailPassword)

         to_addr = "xxxxx@xx.com"
         subject = sys.argv[1]
         body = sys.argv[2]
         try:
             msg = MIMEMultipart()
             msg['From'] = gmailUser
             msg['To'] = to_addr
             msg["Content-type"] = "text/html"
             sub = subject
             msg['Subject'] = sub
             body = body

             msg.attach(MIMEText(body, 'html'))
             mailServer.sendmail(gmailUser, to_addr, msg.as_string())
         except:
             write_exception("send exception")

         mailServer.close()
     except:
          write_exception("send exception1")
  • 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-06-06T14:12:09+00:00Added an answer on June 6, 2026 at 2:12 pm

    If you insist on sending HTML, you need HTML line breaks:

    import cgi
    # escape special HTML characters
    body = cgi.escape(body)
    # use HTML line breaks
    body = body.replace("\r\n", "\n").replace("\n", "<br />\n")
    

    But probably you need neither Multipart nor HTML, so you can just use smtplib.SMTP.sendmail:

    headers = (('From', gmailUser), 
               ('To', to_addr), 
               ('Subject', subject))
    
    # normalize newlines to CR+LF, as required by SMTP
    body = body.replace("\r\n", "\n").replace("\n", "\r\n")
    
    msg = '\r\n'.join("%s: %s" % kv for kv in headers) + '\r\n'*2 + body
    
    mailServer.sendmail(gmailUser, [to_addr], msg)
    

    Also, you should not supply the file contents via the command line, because the command line is length-restricted. Instead you should supply the file via STDIN, like in python ... < /tmp/alert.txt and read it via

    import sys
    body = sys.stdin.read()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case, my file contents look like this a b
My file is xml.txt with following contents: books.xml news.xml mix.xml if I use readline()
I use the following code to copy the content of an XML file into
I have the following contents in my XML file: <items> <item id=1><content><![CDATA[<p>string</p>]]></content></item> </items> I
So I have the following .htaccess file contents from my other project which is
Let's say there is a file called myfile.txt with the following contents: one two
Supposed a text file named name.txt . there are some contents as the following
I have a script that generates a csv file using the following code: header('Content-type:
I have a python script that will take each file in a directory, iterate
I have a file with the following contents: WORD1 WORD2 WORD3 How can I

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.