-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: Strongly Bad Emails

Понедельник, 08 Мая 2017 г. 13:30 + в цитатник

If you want to send emails from a Java program, you might be tempted to use the javax.mail package, which contains objects for doing exactly that. Its a relatively straightforward API, and while its a bit verbose, thats hardly unusual for Java. You just wrap it up in a convenience function based on how you need to call it, and reuse that, right?

Well, PHP, an obviously superior language, already did that work. Theres a built-in mail function, which sends emails. It uses your php.ini file to figure out what SMTP service to use, making the parameters to the function more obvious.

Chris had a co-worker that really loved the… elegance… of PHPs solution to this problem, and thus, when they needed to send emails from Java, they did it this way:

public static void sendEmail(String log, String status) throws Exception {
        String host = "altered.host";
        //run wget
        String url = "http://" +host +"/atcoEmail.php?subject=TIS REPORT - " + status + "&body=" + log;
        String newUrl = url.replace(" ", "~");
        System.out.println(newUrl);
        Runtime.getRuntime().exec("wget -O - ".concat(newUrl).concat("> /dev/null 2>&1"));
}

And dont worry about security, this program was being run as root. What could go wrong?

[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!

http://thedailywtf.com/articles/strongly-bad-emails

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку