{"id":35964,"date":"2018-02-06T03:01:34","date_gmt":"2018-02-05T17:01:34","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=35964"},"modified":"2018-02-05T21:05:26","modified_gmt":"2018-02-05T11:05:26","slug":"java-command-line-email-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-command-line-email-primer-tutorial\/","title":{"rendered":"Java Command Line Email Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/javaMailTo.jpg\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Java Command Line Email Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/javaMailTo.jpg\" title=\"Java Command Line Email Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Java Command Line Email Primer Tutorial<\/p><\/div>\n<p>Became glad that we&#8217;d talked about the incredibly useful Linux <a target=_blank title='mailx' href='http:\/\/linux.die.net\/man\/1\/mailx'><i>mailx<\/i><\/a> command when we presented <a title='Linux mailx Primer Tutorial' href='#lpt'>Linux mailx Primer Tutorial<\/a>.  To wait this long to have presented some information about this gem of a (Linux or Unix or Mac OS X (like BSD)) command line command would be pretty bad.  All that water under the bridge to today, and we come at a command line (for us, a Mac OS X Terminal application one) <a target=_blank title='Java' href='https:\/\/java.com\/download'>Java<\/a> (<a target=_blank title='Java URLConnection information' href='https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/net\/URLConnection.html'>URLConnection<\/a> <a target=_blank title='mailto information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tryit.asp?filename=tryhtml_link_mailto'><i>mailto:<\/i><\/a> URL (ie. email client)) emailer.<\/p>\n<p>Our emailer in Java compiled via the incredibly simple <b>mandatory<\/b> and <i>more than likely needed<\/i> and optionally put here or prompted for during the Java program execution part command &#8230;<\/p>\n<p><code><br \/>\njavac <a target=_blank title='javaMailTo.java' href='http:\/\/www.rjmprogramming.com.au\/Java\/javaMailTo.java_GETME'>javaMailTo.java<\/a><br \/>\n<b>java javaMailTo<\/b> <i>mail.optusnet.com.au<\/i> User@users-macbook-pro-2.local rmetcalfe15@gmail.com \"The Subject of it all at Once\" \"The Body of it all at Once\"<br \/>\n<\/code><\/p>\n<p> &#8230; those arguments being &#8230;<\/p>\n<ul>\n<li><b>java<\/b> &#8230; Java engine<\/li>\n<li><b>javaMailTo<\/b> &#8230; Java class (program) that is the output of the Java &#8220;javac&#8221; compiler&#8217;s work<\/li>\n<li><i>mail.optusnet.com.au<\/i> &#8230; mailhost to use, which in our case points at our ISP (Optus) mail server (for a Mac OS X Mail application setup on this MacBook Pro we are sending emails from (the command line of)) &#8230; as looked up at <a target=_blank title='Optus mailhost advice' href='http:\/\/www.optus.com.au\/shop\/support\/answer\/using-an-email-application-with-optusnet-email?requestType=NormalRequest&#038;id=1434&#038;typeId=5'>this Optus advice link<\/a><\/li>\n<li>User@users-macbook-pro-2.local &#8230; a From: value (email address) that reflects our username of use &#8230; initially got this wrong as being the same as To: below, and in that scenario the email went to the Spam folder for me, and tweaked that this From: should be that Spam email&#8217;s sender &#8230; do that and the email no longer goes to Spam<\/li>\n<li>rmetcalfe15@gmail.com &#8230; a To: email address<\/li>\n<li>&#8220;The Subject of it all at Once&#8221; &#8230; a Subject: of several words can be encased by double quotes<\/li>\n<li>&#8220;The Body of it all at Once&#8221; &#8230; a Body (of email) section finishes off the requirements<\/li>\n<\/ul>\n<p>Not as cute to use as <i>mailx<\/i> but tailorable for your own purposes perhaps?!<\/p>\n<p>We would like to thank the wonderful Java Examples in a Nutshell by David Flanagan (ISBN: 1-56592-371-5) for the basis in code of today&#8217;s Java.<\/p>\n<p>You might want to also read <a target=_blank title='Windows and Mac Command Line Gmail Email Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/windows-and-mac-command-line-gmail-email-primer-tutorial\/'>Windows and Mac Command Line Gmail Email Primer Tutorial<\/a>.<\/p>\n<hr>\n<p id='lpt'>Previous relevant <a target=_blank title='Linux mailx Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-mailx-primer-tutorial\/'>Linux mailx Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux mailx Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg\" title=\"Linux mailx Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux mailx Primer Tutorial<\/p><\/div>\n<p>Think Linux and you may not associate it with email, but Linux can be excellent for many email requirements, especially using mailx and uuencode.   The use of uuencode allows you to give your email an attachment, and the mailx -s switch for the subject of the email can be used for both the purpose it was meant for, that is to establish an email subject, and with a stretch of imagination of usage, the body text, because of the quirk whereby anything after the first line of the subject will spill over into the body text of the email.   So, am sure there would be limits to the length of this body text, but you can often be brief when there is a good attachment to provide your email recipient.   Naturally, in the day and age of worry about computer viruses, your attachment will most likely be vetted by the receiving email client software for viability, so be aware of this.   Other than all that, this method of sending emails is potentially very powerful.  Notice that great way Linux and Unix can use `cat body.txt` type of syntax to embed one command within another &#8230; sometimes Linux is so simple, powerful, brilliant!   You may have noticed how short all the commands in Linux and Unix tend to be, and that is because it was intended to be short and powerful, and this is brilliant.<\/p>\n<p><b>Background reading for tutorial:<\/p>\n<ul>\n<li><a target=_blank title='mailx' href='http:\/\/linux.die.net\/man\/1\/mailx'>mailx<\/a><\/li>\n<li><a target=_blank title='uuencode' href='http:\/\/linux.die.net\/man\/1\/uuencode'>uuencode<\/a><\/li>\n<\/ul>\n<p><\/b>\n<\/p>\n<p>Here is a tutorial that introduces you to some email with attachment, subject and body text from the Linux <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg'>command line<\/a>.<\/p>\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4673' onclick='var dv=document.getElementById(\"d4673\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4673' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d35964' onclick='var dv=document.getElementById(\"d35964\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/java\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35964' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Became glad that we&#8217;d talked about the incredibly useful Linux mailx command when we presented Linux mailx Primer Tutorial. To wait this long to have presented some information about this gem of a (Linux or Unix or Mac OS X &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-command-line-email-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[1885,1835,234,242,319,380,503,644,649,725,740,885,997,1252,1319],"class_list":["post-35964","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-argument","tag-arguments","tag-command-line","tag-compiler","tag-desktop","tag-email","tag-gmail","tag-java","tag-javac","tag-mac-os-x","tag-mailx","tag-operating-system-2","tag-programming","tag-terminal","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35964"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=35964"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35964\/revisions"}],"predecessor-version":[{"id":35969,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35964\/revisions\/35969"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=35964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=35964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=35964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}