2016-04-11 20 views
2

、カール、SHを介した電子メールのテキストとしてファイルの内容を送信します。は私が何を私は以下の持っていることだけで正常に動作し自分自身のメール</p> <p>を送信するために使用したい、このsend_update.shファイルを持っているmailgun

しかし、私は、変数var=cat update.txt-F text=$varを作ってみましたが、それはちょうど私にエラーを与える

UPDATE.TXTファイルの内容にテキストを変更したい:悲しいこと

"message": "Need at least one of 'text' or 'html' parameters specified" 

#!/bin/sh 
curl -s --user 'api:key-mykey' \ 
    http:mail-gun-api 
    -F from=... 
    -F to=... 
    -F subject='Hello My name is here' \ 
    -F text='First email!' 

Google Compute Engineが許可していないため、通常のsendmailを使用することはできません。使用できるコマンドの出力として変数を設定するのbashスクリプトの場合

答えて

4

、:

var=$(cat /full/path/to/file/update.txt) 

あなたがこれを行う場合は、UPDATE.TXTファイルの内容は今変数$varに割り当てられます。ファイルが現在の作業ディレクトリにある場合は、おそらくupdate.txtへの完全なパスを含める必要はありません

-F text=$(cat /full/path/to/file/update.txt) 

:あなたは完全にかかわらず、$var変数を避けたい、とのような何かをするかもしれません。

+0

お返事ありがとうございますが、私はtxtファイルの最初のスペースまで印刷していることがわかりました。あなたはこれを解決する方法を知っていますか? – Rorschach

+1

@Rorschachこれは、curlが提供された引数で実行される前に、Bashによって実行された[Word Splitting](http://mywiki.wooledge.org/WordSplitting)の結果です。さらに、ここで 'cat'を使う必要はありません。フォームにファイルの内容を含める方法については 'man curl'をチェックし、' -F、--form'を検索してください。 –

1

curlはこの動作を内部的にサポートしています。

-F, --form <name=content> 
     (HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. 
     This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with 
     the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field 
     from a file. 

     Example, to send your password file to the server, where 'password' is the name of the form-field to which /etc/passwd will be the input: 

     curl -F [email protected]/etc/passwd www.mypasswords.com 

     To read content from stdin instead of a file, use - as the filename. This goes for both @ and < constructs. Unfortunately it does not support reading the file from a named pipe or similar, as 
     it needs the full size before the transfer starts. 

     You can also tell curl what Content-Type to use by using 'type=', in a manner similar to: 

     curl -F "[email protected];type=text/html" url.com 

     or 

     curl -F "name=daniel;type=text/foo" url.com 

     You can also explicitly change the name field of a file upload part by setting filename=, like this: 

     curl -F "[email protected];filename=nameinpost" url.com 

     If filename/path contains ',' or ';', it must be quoted by double-quotes like: 

     curl -F "[email protected]\"localfile\";filename=\"nameinpost\"" url.com 

     or 

     curl -F '[email protected]"localfile";filename="nameinpost"' url.com 

     Note that if a filename/path is quoted by double-quotes, any double-quote or backslash within the filename must be escaped by backslash. 

     See further examples and details in the MANUAL. 

     This option can be used multiple times. 

編集:コメント欄で説明したように

OPは、-F text="</path/to/update.txt"とそれを解決man curl(カールバージョン7.48.0)から引用

+0

悲しいことに、 "message": "'text'パラメータは文字列ではありません。" – Rorschach

+0

"それはどういう意味ですか?あなたは何を実行しているのか見てもらえますか? –

+0

'-F text = @/path/to/update.txt' – Rorschach

関連する問題

 関連する問題