<< Masa.20101220-debug-ch_oddb_org-generics_xls | 2010 | Masa.20101216-update-import_de_oddb_org_Festbe_Zubef >>
suspend
suspend
What is smtp_tls?
References
Confirm
test.rb
require 'net/smtp'
require 'smtp_tls'
require 'rmail'
def make_header(subject, from, recipients, charset="utf8")
mpart = RMail::Message.new
header = mpart.header
header.to = recipients
header.from = from
header.subject = subject
header.date = Time.now
header.add('Content-Type', 'text/plain', nil,
'charset' => charset)
return mpart
end
def sendmail(subject, message, from, recipients, charset="utf8")
mpart = make_header(subject, from, recipients, charset)
mpart.body = message.join("\n")
smtp_server = "smtp.gmail.com"
smtp_port = 25
smtp_domain = "ywesee.com"
smtp_user = from
smtp_pass = "ppp"
smtp_authtype = :plain
smtp = Net::SMTP.new(smtp_server, smtp_port)
smtp.start(smtp_domain, smtp_user, smtp_pass,
smtp_authtype) do |server|
recipients.each do |recipient|
server.sendmail(mpart.to_s, from, recipient)
end
end
end
recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"
sendmail(subject, message, from, recipients, charset)
Note
Experiment (install and use the latest version of smtp_tls)
Install
masa@masa ~/work $ sudo gem install smtp_tls
Run a sample of net/smtp
masa@masa ~/work $ cat test.rb
require 'net/smtp'
require 'smtp_tls'
require 'rmail'
def make_header(subject, from, recipients, charset="utf8")
mpart = RMail::Message.new
header = mpart.header
header.to = recipients
header.from = from
header.subject = subject
header.date = Time.now
header.add('Content-Type', 'text/plain', nil,
'charset' => charset)
return mpart
end
def sendmail(subject, message, from, recipients, charset="utf8")
mpart = make_header(subject, from, recipients, charset)
mpart.body = message.join("\n")
smtp_server = "smtp.gmail.com"
smtp_port = 25
smtp_domain = "ywesee.com"
smtp_user = from
smtp_pass = "ppp"
smtp_authtype = :plain
Net::SMTP.start(smtp_server, smtp_port,
smtp_domain, smtp_user, smtp_pass,
smtp_authtype) do |smtp|
recipients.each do |recipient|
smtp.sendmail(mpart.to_s, from, recipient)
end
end
end
recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"
sendmail(subject, message, from, recipients, charset)
Result
masa@masa ~/work $ ruby test.rb
/usr/lib64/ruby/1.8/net/smtp.rb:579:in `auth_plain': 530 5.7.0 Must issue a STARTTLS command first. f52sm465370wes.35 (Net::SMTPAuthenticationError)
from /usr/lib64/ruby/1.8/net/smtp.rb:573:in `__send__'
from /usr/lib64/ruby/1.8/net/smtp.rb:573:in `authenticate'
from /usr/lib64/ruby/1.8/net/smtp.rb:410:in `do_start'
from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:41:in `send'
from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:41:in `start'
from /usr/lib64/ruby/gems/1.8/gems/smtp_tls-1.0.3/lib/smtp_tls.rb:24:in `start'
from test.rb:30:in `sendmail'
from test.rb:47
Note
Experiment
test.rb
require 'net/smtp'
require 'smtp_tls'
require 'rmail'
def make_header(subject, from, recipients, charset="utf8")
mpart = RMail::Message.new
header = mpart.header
header.to = recipients
header.from = from
header.subject = subject
header.date = Time.now
header.add('Content-Type', 'text/plain', nil,
'charset' => charset)
return mpart
end
def sendmail(subject, message, from, recipients, charset="utf8")
mpart = make_header(subject, from, recipients, charset)
mpart.body = message.join("\n")
smtp_server = "smtp.gmail.com"
smtp_port = 25
smtp_domain = "ywesee.com"
smtp_user = from
smtp_pass = "ppp"
smtp_authtype = :plain
smtp = Net::SMTP.new(smtp_server, smtp_port)
smtp.enable_starttls
smtp.start(smtp_domain, smtp_user, smtp_pass, smtp_authtype) do |server|
recipients.each do |recipient|
server.sendmail(mpart.to_s, from, recipient)
end
end
end
recipients = ["mhatakeyama@ywesee.com"]
from = "mhatakeyama@ywesee.com"
message = ["hello, world", "by masa"]
subject = "test mail"
charset = "utf8"
sendmail(subject, message, from, recipients, charset)
Result
masa@masa ~/work $ ruby test.rb masa@masa ~/work $
Note
hello, world by masa
Conclusion
Note
Experiment
src/testenrivonment.rb
#!/usr/bin/env ruby
puts 'loading testenvironment'
class BbmbApp < SBSM::DRbServer
puts "disabling UPDATER"
remove_const :RUN_UPDATER
# remove_const :RUN_STATISTICS
RUN_UPDATER = false
# RUN_STATISTICS = false
print "BbmbApp::RUN_UPDATER="
p RUN_UPDATER
print "BbmbApp::RUN_STATISTICS="
p RUN_STATISTICS
end
module BBMB
class CustomBehaviorGag < CustomBehavior
remove_const :MAIL_RECIPIENTS
remove_const :MAIL_RECIPIENTS_CC
remove_const :MAIL_INJECT_RECIPIENTS
remove_const :MAIL_PDF_RECIPIENTS
remove_const :MAIL_PDF_RECIPIENTS_CC
remove_const :MAIL_PDF_FROM
remove_const :REMOTE_ACCESS
MAIL_RECIPIENTS = ['mhatakeyama@ywesee.com']
MAIL_RECIPIENTS_CC = []
MAIL_INJECT_RECIPIENTS = ['mhatakeyama@ywesee.com']
MAIL_PDF_RECIPIENTS = ['mhatakeyama@ywesee.com']
MAIL_PDF_RECIPIENTS_CC = []
MAIL_PDF_FROM = 'mhatakeyama@ywesee.com'
REMOTE_ACCESS = 'ftp://ftp_user1:ppp@localhost'
print "BBMB::CustomBehaviorGag::MAIL_RECIPIENTS="
p BBMB::CustomBehaviorGag::MAIL_RECIPIENTS
end
end
def mail_send(mail, from, to)
p "getin mail_send"
print "from=", from, "\n"
print "to=", to, "\n"
unless to.grep(/mhatakeyama/)
p "Oh, my GOD!"
exit
end
#smtp = Net::SMTP.new('localhost')
smtp = Net::SMTP.new('smtp.google.com', 25)
#smtp.start {
smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
begin
p "gefore sendmail"
smtp.sendmail(mail.encoded(), from, to)
p "after sendmail"
rescue Net::SMTPFatalError => error
Result
/usr/lib64/ruby/1.8/timeout.rb:60:in `new': execution expired (Timeout::Error)
from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
from /usr/lib64/ruby/1.8/net/smtp.rb:392:in `do_start'
from /usr/lib64/ruby/1.8/net/smtp.rb:377:in `start'
from /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:360:in `mail_send'
from /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:418:in `mail_statistics'
from /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `send'
from /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `method_missing'
... 9 levels...
from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:514:in `run_statistics'
from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:299:in `initialize'
from bin/bbmbd:10:in `new'
from bin/bbmbd:10
Note
Experiment
def mail_send(mail, from, to)
#smtp = Net::SMTP.new('localhost')
smtp = Net::SMTP.new('smtp.gmail.com', 25)
#smtp.start {
smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
begin
#raise Net::SMTPFatalError, "masa error"
smtp.sendmail(mail.encoded(), from, to)
rescue Net::SMTPFatalError => err
error = TMail::Mail.new
error.from = from
error.to = 'mhatakeyama@ywesee.com'
error.subject = "Mail-Delivery Error!"
error.date = Time.now
etext = TMail::Mail.new
etext.set_content_type('text', 'plain', 'charset'=>'iso-8859-1')
etext.body = [
# errror,
# error.message,
# error.backtrace,
err,
err.message,
err.backtrace,
].join("\n")
error.parts << etext
smtp.sendmail(error.encoded(), from, to)
end
}
end
Run bbmb.ch/bin/bbmbd
Result
Monatlicher Export verkaufte Produkte: GXXXXpharm-17.12.2010 Verkaufte Produkte von 01. bis 30.11.2010
Notes
Error mail check
def mail_send(mail, from, to)
#smtp = Net::SMTP.new('localhost')
smtp = Net::SMTP.new('smtp.gmail.com', 25)
#smtp.start {
smtp.start("ywesee.com", "mhatakeyama@ywesee.com", "ppp", :plain) {
begin
raise Net::SMTPFatalError, "masa error"
smtp.sendmail(mail.encoded(), from, to)
rescue Net::SMTPFatalError => err
error = TMail::Mail.new
error.from = from
error.to = 'mhatakeyama@ywesee.com'
error.subject = "Mail-Delivery Error!"
error.date = Time.now
etext = TMail::Mail.new
etext.set_content_type('text', 'plain', 'charset'=>'iso-8859-1')
etext.body = [
# errror,
# error.message,
# error.backtrace,
err,
err.message,
err.backtrace,
].join("\n")
error.parts << etext
smtp.sendmail(error.encoded(), from, to)
end
}
end
Result
masa error masa error /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:357:in `mail_send' /usr/lib64/ruby/1.8/net/smtp.rb:378:in `start' /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:354:in `mail_send' /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:414:in `mail_statistics' /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `send' /home/masa/ywesee/bbmb.ch/src/model/reseller.rb:48:in `method_missing' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:613:in `statistics' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:611:in `each' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:611:in `statistics' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:609:in `loop' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:609:in `statistics' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:516:in `run_statistics' /usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `initialize' /usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `__mnemonic_new__' /usr/lib64/ruby/site_ruby/1.8/mnemonic/Mnemonic.rb:207:in `new' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:513:in `run_statistics' /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:299:in `initialize' bin/bbmbd:10:in `new' bin/bbmbd:10
Note
Commit
Reference
Next
suspend
Reference
Memo
Question
Note
grep search
masa@masa ~/ywesee/bbmb $ grep -ri smtp *
lib/bbmb/config.rb: 'smtp_authtype' => nil,
lib/bbmb/config.rb: 'smtp_helo' => 'localhost.localdomain',
lib/bbmb/config.rb: 'smtp_pass' => nil,
lib/bbmb/config.rb: 'smtp_port' => 25,
lib/bbmb/config.rb: 'smtp_server' => 'mail.bbmb.ch',
lib/bbmb/config.rb: 'smtp_user' => nil,
lib/bbmb/util/mail.rb:require 'net/smtp'
lib/bbmb/util/mail.rb: Net::SMTP.start(config.smtp_server, config.smtp_port, config.smtp_helo,
lib/bbmb/util/mail.rb: config.smtp_user, config.smtp_pass,
lib/bbmb/util/mail.rb: config.smtp_authtype) { |smtp|
lib/bbmb/util/mail.rb: smtp.sendmail(message.to_s, from, [to, cc].flatten.compact)
Note
Summary
Next
Try to run bin/bbmbd
masa@masa ~/ywesee/bbmb $ bin/bbmbd
/usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:118:in `initialize': FATAL: database "bbmb" does not exist (DBI::OperationalError)
from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `new'
from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `connect'
from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:448:in `connect'
from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:221:in `connect'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:60:in `_connect'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `times'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `_connect'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `synchronize'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:19:in `initialize'
from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38:in `new'
from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38
from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from bin/bbmbd:18
Note
References
Check bbmbd working locally
masa@masa ~/ywesee/bbmb $ bin/bbmbd config="config.yml"
masa@masa ~/ywesee/yus $ bin/yusd server_url="druby://localhost:12001"
config.yml
--- error_recipients: - mhatakeyama@ywesee.com bbmb_dir: /home/masa/ywesee/bbmb db_name: sandoz_bbmb db_user: sandoz db_pass: sandoz importers: "Kunden.txt": "CustomerImporter" load_files: # - 'bbmb/sandoz' - 'bbmb/util/csv_importer' log_level: DEBUG mail_order_to: mhatakeyama@ywesee.com mail_order_from: mhatakeyama@ywesee.com name: "Bbmb(Masa)" smtp_server: mail.ywesee.com smtp_authtype: :plain smtp_user: 'mhatakeyama@ywesee.com' smtp_pass: ppp target_format: csv #ydim_config: /var/www/sandoz.bbmb.ch/etc/ydim.yml #ydim_id: 51 inject_error_body: | inject_error_body inject_error_subject: 'Bestellung "%s" mit fehlendem Kunden: "%s"' inject_error_from: 'mhatakeyama@ywesee.com' inject_error_to: 'mhatakeyama@ywesee.com' mail_confirm_from: 'mhatakeyama@ywesee.com' mail_confirm_reply_to: 'mhatakeyama@ywesee.com' mail_confirm_subject: "Masa: Auftragsbestätigung %s" mail_confirm_lines: - "%3i x %-40s ā %6.2f, total %7.2f" - "%3i x %-40s ā %6.2f, total %7.2f" - "%3i x %-40s a %6.2f, totale %7.2f" mail_confirm_body: | mail_confirm_body confirm_error_body: | confirm_error_body confirm_error_subject: Kunde "%s" ohne hinterlegte Email-Adresse im Masa E-shop confirm_error_from: 'mhatakeyama@ywesee.com' confirm_error_to: 'mhatakeyama@ywesee.com' invoice?: false update?: true new_customer_mail: "mailto:mhatakeyama@ywesee.com?subject=Neukunde BBMB - bitte Passwort generieren" polling_file: '/home/masa/ywesee/bbmb/etc/polling.yml'
/etc/apache2/vhosts.d/04_bbmb_vhost.conf
masa@masa ~/ywesee/bbmb $ cat /etc/apache2/vhosts.d/04_bbmb_vhost.conf <Directory /home/masa/ywesee/bbmb/doc> Options ExecCGI FollowSymlinks Indexes AllowOverride None Order allow,deny Allow from all # SSLRequireSSL # ErrorDocument 403 https://masa.bbmb.ch </Directory> <VirtualHost *:80> DocumentRoot /home/masa/ywesee/bbmb/doc ServerName bbmb.masa.ch DirectoryIndex index.rbx RubyAddPath /home/masa/ywesee/bbmb/src RubyRequire 'sbsm/trans_handler' SetHandler ruby-object RubyTransHandler SBSM::TransHandler.instance # ErrorLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/error_log /home/masa/ywesee/bbmb/log/%Y/%m/%d/error_log" # CustomLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/access_log /home/masa/ywesee/bbmb/log/%Y/%m/%d/access_log" combined # SetEnv DEFAULT_FLAVOR masa_bbmb SetEnv DRB_SERVER druby://localhost:12000 </VirtualHost>
Result

grep search
masa@masa ~/ywesee/bbmb $ grep -r sendmail lib lib/bbmb/util/mail.rb: Mail.sendmail message, from, to, cc lib/bbmb/util/mail.rb: Mail.sendmail(message, from, to) lib/bbmb/util/mail.rb: Mail.sendmail(message, from, to) lib/bbmb/util/mail.rb: Mail.sendmail message, from, to, cc lib/bbmb/util/mail.rb: def Mail.sendmail(message, from, to, cc=[]) lib/bbmb/util/mail.rb:p "getin Mail.sendmail" lib/bbmb/util/mail.rb: smtp.sendmail(message.to_s, from, [to, cc].flatten.compact) lib/bbmb/util/mail.rb: Mail.sendmail(message, from, to, config.mail_confirm_cc) lib/bbmb/util/mail.rb: Mail.sendmail(message, from, to, cc) lib/bbmb/util/mail.rb: Mail.sendmail(message, from, to, cc)
Notes
masa@masa ~/ywesee/bbmb $ grep -r "Mail.send" lib|grep -v mail.rb
lib/bbmb/html/state/login.rb: BBMB::Util::Mail.send_request(input[:email], input[:organisation], body)
lib/bbmb/util/server.rb: BBMB::Util::Mail.send_order(order)
lib/bbmb/util/server.rb: BBMB::Util::Mail.send_confirmation(order)
masa@masa ~/ywesee/bbmb $ grep -r "Mail.notify" lib|grep -v mail.rb
lib/bbmb/util/invoicer.rb: Util::Mail.notify_debug("No invoice necessary", body)
lib/bbmb/util/polling_manager.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/polling_manager.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/polling_manager.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb: BBMB::Util::Mail.notify_inject_error(order, opts)
lib/bbmb/util/server.rb: Mail.notify_error(e)
lib/bbmb/util/server.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb: BBMB::Util::Mail.notify_error(err)
lib/bbmb/util/server.rb: Mail.notify_error(e)
Consideration
Experiment
config.yml (change the following parts)
... smtp_server: smtp.gmail.com smtp_port: 587 ... update?: true ...
require 'bbmb/util/smtp_tls'
...
def run_updater
@updater ||= Thread.new {
loop {
day = Date.today
now = Time.now
if(now.hour >= BBMB.config.update_hour)
day += 1
end
at = Time.local(day.year, day.month, day.day,
# BBMB.config.update_hour)
now.hour, now.min+1)
print "at="
p at
print "now="
p now
secs = at - now
BBMB.logger.debug("updater") {
"sleeping %.2f seconds" % secs
}
sleep(secs)
update
p "done update"
sleep(100000)
}
}
end
...
def update
p "getin BBSB::Util::Server#update"
raise Exception, "masa error"
Updater.run
rescue Exception => e
Mail.notify_error(e)
end
Copy smtp_tls.rb in lib/bbmb/util/
masa@masa ~/ywesee/bbmb $ ls lib/bbmb/util/ csv_importer.rb mail.rb numbers.rb polling_manager.rb smtp_tls.rb transfer_dat.rb invoicer.rb multilingual.rb password_generator.rb server.rb target_dir.rb updater.rb
Run
masa@masa ~/ywesee/bbmb $ bin/bbmbd config="config.yml"
Result
Exception masa error ["/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:162:in `update'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:128:in `run_updater'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:110:in `loop'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:110:in `run_updater'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `initialize'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `new'", "/home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:109:in `run_updater'", "bin/bbmbd:43"]
Commit
Notes
References