Here is how I do it in a bash script:
wp option get wp_smtp_options --format=json | php -r '
$var = json_decode( fgets(STDIN) );
$var->from = "[email protected]";
$var->fromname = "me";
' | wp option set wp_smtp_options --format=json
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.