3 votos

Automator -> enviar archivo al correo electrónico (desde nombre de archivo)

Estoy tratando de crear una acción de carpeta de Automator que envíe un correo electrónico con un archivo adjunto.

En mi carpeta se generarán los archivos con el correo electrónico como nombre: Ejemplo: name@company.com.jpg, othername@othercompany.com.jpg y así sucesivamente.

Lo que necesito es una acción que copie el nombre del archivo, quite la extensión (.jpg), cree un correo electrónico y ponga el nombre del archivo/correo electrónico en el "Para" y luego envíe el correo electrónico.

Ya tengo una versión que funciona en la que se adjunta el archivo al correo electrónico y se rellena el contenido del mismo. Pero no encuentro una solución para copiar el nombre del archivo y especificarlo en la dirección "Para".

Espero que alguien por ahí me pueda ayudar :-)

3voto

Bibou Puntos 520

Lo he intentado con Automator sin conseguirlo haciendo un bucle con los archivos caídos.

Aquí hay una acción de carpeta script que hace lo que quieres, y cómo adjuntarla a una carpeta :

1. Abra el editor de AppleScript

2. Pegue el siguiente script en un nuevo documento

property mail_subject : "An image for you"
property mail_plain_content : "Attached you will the image you required." & return & return & "Best Regards" & return & "Automator"
property mail_html_content : "Attached you will the image you required.<br><br>Best Regards<br>Automator"

on adding folder items to this_folder after receiving these_items
    processItems(these_items)
end adding folder items to

on processItems(these_items)
    repeat with i from 1 to (count of these_items)
        set this_item to item i of these_items
        if isFolder(this_item) then
            processItems(getFolderItems(this_item))
        else
            processFile(this_item)
        end if
    end repeat
end processItems

on processFile(this_file)
    set mail_address to RemoveExtension(getFileName(this_file))
    tell application "Microsoft Outlook"
        set newMessage to make new outgoing message with properties {subject:mail_subject, plain text content:mail_plain_content, content:mail_html_content}
        tell newMessage
            make new recipient with properties {email address:{address:mail_address}}
            make new attachment with properties {file:this_file as alias}
            send
        end tell
        activate
    end tell
end processFile

on isFolder(this_item)
    tell application "System Events" to return (exists folder (this_item as string))
end isFolder

on RemoveExtension(this_name)
    -- This function comes from :
    -- http://www.macosxautomation.com/applescript/sbrt/index.html
    if this_name contains "." then
        set this_name to (the reverse of every character of this_name) as string
        set dot_offset to the offset of "." in this_name
        set this_name to (text (dot_offset + 1) thru -1 of this_name)
        set this_name to (the reverse of every character of this_name) as string
    end if
    return this_name
end RemoveExtension

on getExtension(this_name)
    if this_name contains "." then
        set this_name to (the reverse of every character of this_name) as string
        set dot_offset to the offset of "." in this_name
        set this_name to (text 1 thru (dot_offset - 1) of this_name)
        set this_name to (the reverse of every character of this_name) as string
        return this_name
    else
        return ""
    end if
end getExtension

on getFileName(this_file)
    tell application "Finder" to return name of this_file
end getFileName

on getFolderItems(this_folder)
    tell application "Finder" to return items of this_folder
end getFolderItems

3. Guárdalo en tu ~/Library/scripts/Folder Action scripts Carpeta

Menú Archivo > Guardar

Vaya a la carpeta correcta: pulse cmd + G y pegar:
~/Library/scripts/Folder Action scripts
y haga clic en Ir a

Guardar como : Imagen - Correo electrónico usando el nombre como dirección.scpt (por ejemplo)
Formato : script

4. Cree una nueva carpeta que será vigilada para los elementos añadidos

5. Asociar el script a la carpeta

En el Finder, haga clic con el botón derecho del ratón en su carpeta y seleccione Servicios > Configuración de las acciones de la carpeta Seleccione el nuevo creado Imagen - Correo electrónico usando el nombre como dirección.scpt script

Ya está, suelta un archivo cuyo nombre es una dirección, el correo será enviado.

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X