Executing shell mail command using python

sandy

I have used the following code to send an email as suggested in one of the post on the similar topic. But the mail has not been sent. Any suggestions?

import subprocess
recipient = '[email protected]'
subject = 'test'
body = 'testing mail through python'
def send_message(recipient, subject, body):
    process = subprocess.Popen(['mail', '-s', subject, recipient],
                               stdin=subprocess.PIPE)
    process.communicate(body)

print("sent the email")
lqhcpsgbl

Your function may not be called, try this code :

import subprocess

recipient = '[email protected]'
subject = 'test'
body = 'testing mail through python'

def send_message(recipient, subject, body):
    try:
      process = subprocess.Popen(['mail', '-s', subject, recipient],
                               stdin=subprocess.PIPE)
    except Exception, error:
      print error
    process.communicate(body)

send_message(recipient, subject, body)

print("sent the email")

May works. Good luck.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

executing shell command using shell script

From Dev

Python - Executing shell command does not work on Linux

From Dev

Executing a 'perl command' from shell and executing the same command from perl script using system command

From Dev

Shell command not executing in Java

From Dev

Shell command in VBA not using the PATH variable (executing .jar from VBA)

From Dev

Executing shell command not working in AWS

From Dev

Executing a basic shell command in Elixir

From Dev

Executing Shell command in Makefile rule

From Dev

Executing shell command not working in AWS

From Dev

Executing Shell command in Makefile rule

From Dev

Executing a command using JSch

From Dev

Executing a local shell function on a remote host over ssh using Python

From Dev

executing shell script using subprocess.Popen in Python?

From Dev

Python not executing write command

From Dev

curl command not executing via shell script in bash

From Dev

Getting the (parent) process executing the command in Linux shell

From Dev

Executing long command with groovy on linux shell?

From Dev

errors executing bash command in shell script variable

From Dev

tmux titles-string not executing shell command

From Dev

Executing multiple line shell command in php

From Dev

always prompt the user before executing a command in the shell

From Dev

Executing an if else shell command from perl

From Dev

always prompt the user before executing a command in the shell

From Dev

Getting the (parent) process executing the command in Linux shell

From Dev

errors executing bash command in shell script variable

From Dev

Shell script not executing a command returned from a function

From Dev

Error while executing awk command in shell script

From Dev

curl command not executing via shell script in bash

From Dev

Executing shell command after Webpack post build

Related Related

  1. 1

    executing shell command using shell script

  2. 2

    Python - Executing shell command does not work on Linux

  3. 3

    Executing a 'perl command' from shell and executing the same command from perl script using system command

  4. 4

    Shell command not executing in Java

  5. 5

    Shell command in VBA not using the PATH variable (executing .jar from VBA)

  6. 6

    Executing shell command not working in AWS

  7. 7

    Executing a basic shell command in Elixir

  8. 8

    Executing Shell command in Makefile rule

  9. 9

    Executing shell command not working in AWS

  10. 10

    Executing Shell command in Makefile rule

  11. 11

    Executing a command using JSch

  12. 12

    Executing a local shell function on a remote host over ssh using Python

  13. 13

    executing shell script using subprocess.Popen in Python?

  14. 14

    Python not executing write command

  15. 15

    curl command not executing via shell script in bash

  16. 16

    Getting the (parent) process executing the command in Linux shell

  17. 17

    Executing long command with groovy on linux shell?

  18. 18

    errors executing bash command in shell script variable

  19. 19

    tmux titles-string not executing shell command

  20. 20

    Executing multiple line shell command in php

  21. 21

    always prompt the user before executing a command in the shell

  22. 22

    Executing an if else shell command from perl

  23. 23

    always prompt the user before executing a command in the shell

  24. 24

    Getting the (parent) process executing the command in Linux shell

  25. 25

    errors executing bash command in shell script variable

  26. 26

    Shell script not executing a command returned from a function

  27. 27

    Error while executing awk command in shell script

  28. 28

    curl command not executing via shell script in bash

  29. 29

    Executing shell command after Webpack post build

HotTag

Archive