Esta entrada también está disponible en: Inglés
Con esta función podrás enviar emails utilizando el comando mailx, incluso con archivos adjuntos.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#!/bin/sh send_email() { # # Proceso de parámetros # DIRECCION="$1" ASUNTO="" MENSAJE="" if [ $# -ge 2 ]; then if [ "$2" != "-" ]; then ASUNTO="$2" fi fi if [ $# -ge 3 ]; then if [ "$3" != "-" ]; then MENSAJE="$3" fi fi ADJUNTO="" if [ $# -ge 4 ]; then if [ "$4" != "-" ]; then ADJUNTO="$4" fi fi # # Envío del email # ( echo "$MENSAJE"; if [ "$ADJUNTO" != "" ]; then archivo=`echo $ADJUNTO|cut -d'~' -f1` nombre=`echo $ADJUNTO|cut -d'~' -f2` if [[ "$archivo" == "$nombre" || "$nombre" == "" ]]; then nombre=`basename $archivo` fi if [ -f "$archivo" ]; then uuencode "$archivo" "$nombre"; fi fi; ) | mailx -s "$ASUNTO" "$DIRECCION" } send_email "tuemail@tudominio.com" "Asunto del mensaje" "Este es el cuerpo del mensaje" "archivo_adjunto.txt" |