Pages

Wednesday, August 21, 2024

Email from vim v2

Improved upon it by redetermining the data structure on integromat to include recipient (tried before but the feild wasn't showing up but now it is so im using it.) It was cool being able to send yourself emails but now you can send anybody an email instead of having to manually go in and edit it in integromat. The trade off now is its a bit more stuff to type. Maybe it was better before just automatically sending it to yourself. who can remember everybodys emails anyway?

Remember to swap out YOURWEBHOOKGOESHERE for your webhookadress in the vimscript


"
"
"### EMAIL FROM WITHIN VIM###"
"
"
"
function! Email()
    " Prompt for the recipient email address
    let l:recipient = input('Enter the recipient email address: ')
    
    " Prompt for the title
    let l:title = input('Enter the title: ')
    
    " Get the current buffer content
    let l:buf_content = join(getline(1, '$'), "\n")

    " Define the body as the entire buffer content
    let l:body = l:buf_content

    " Create a dictionary for the JSON payload
    let l:json_dict = {
    \ 'recipient': l:recipient,
    \ 'title': l:title,
    \ 'body': l:body
    \ }

    " Convert the dictionary to JSON
    let l:json_payload = json_encode(l:json_dict)
    
    " Create a temporary file to hold the JSON payload
    let l:tmpfile = tempname()
    call writefile([l:json_payload], l:tmpfile)

    " Prepare the curl command with the new URL
    let l:cmd = 'curl -X POST https://hook.us1.make.com/ -H "Content-Type: application/json" -d @' . shellescape(l:tmpfile)

    " Run the curl command
    let l:output = system(l:cmd)

    " Clean up the temporary file
    call delete(l:tmpfile)

    " Show the output or errors
    echo l:output
endfunction

" Create a command to run the function
command! Email call Email()

No comments:

Post a Comment