2016-09-29 4 views
0

このスクリプトを使用すると、メッセージを入力して、それは新しい行にジャンプし、特定の単語があなたが取得を通じてユーザー入力を取得し、それが指定した文字列と同じであるかどうかを確認することができReturnキーはルビーで電子メールを送信しますが、メールを送信する代わりに新しい行にジャンプする方法

require 'mail' 
require 'colorize' 
options = { :address    => "smtp.gmail.com", 
     :port     => 587, 
     :user_name   => '[email protected]', 
     :password    => 'mypass', 
     :authentication  => 'plain', 
     :enable_starttls_auto => true } 
    ail.defaults do 
delivery_method :smtp, options 
end 

Mail.deliver do 
to '[email protected]' 

from '[email protected]' 


subject 'hello' 
puts "[!] IMPORTANT type 'SND' in full uppercase then PRESS ENTER to  send the Email".yellow 
puts"Enter Your Message Below".colorize(:light_blue) 
print "Message > ".colorize(:light_blue) ##entering message body here 
body gets ##sends the mail as soon as i hit enter 

end 

答えて

0

この実行する必要があります。私は体は私が押しmail..whenが入力した受信したときに、それは新しい行にスキップん表示されません。しかし、今入力したが、押したときに

Mail.deliver do 
    to '[email protected]' 
    from '[email protected]' 
    subject 'hello' 

    puts "[!] IMPORTANT type 'SND' in full uppercase then PRESS ENTER to  send the Email".yellow 
    puts"Enter Your Message Below".colorize(:light_blue) 
    print "Message > ".colorize(:light_blue) ##entering message body here 

    the_body = "" 
    loop do 
    line = gets 
    break if line.include? "SND" 
    the_body << line 
    end 

    body the_body 
end 
+0

本当にありがとうございました:D –

0

を入力された場合にのみメールを送信するので、どのように私はそれを可能にすることができますif条件でメールを送信し、ユーザーにメールを送信します。 それはあなたがメールを送ると呼ばれる機能で上記のコードを入れて、独立して、それを呼び出すことができます。この

require 'mail' 
require 'colorize' 
options = { :address    => "smtp.gmail.com", 
     :port     => 587, 
     :user_name   => '[email protected]', 
     :password    => 'mypass', 
     :authentication  => 'plain', 
     :enable_starttls_auto => true } 
    ail.defaults do 
delivery_method :smtp, options 
end 
def sendMail() 
    Mail.deliver do 
    to '[email protected]' 

    from '[email protected]' 


    subject 'hello' 
    puts "[!] IMPORTANT type 'SND' in full uppercase then PRESS ENTER  to  send the Email".yellow 
    puts"Enter Your Message Below".colorize(:light_blue) 
    print "Message > ".colorize(:light_blue) ##entering message body here 
    body gets ##sends the mail as soon as i hit enter 

    end 
end 


input = gets.chomp 
if input == 'Send Email' 
    sendEmail() 
else 
    puts "\n" 
end 

ようになります。

+0

を、それはまだメールを送信1秒後に終了し、メールを送信する –

+0

あなたはコードを書き直してif文と関数を含めることができますか?どこが間違っているのか分かりません –

+0

まだジャンプしているスクリプトを実行するとすぐに入力=取得し、私は '電子メールを送信'またはそれ以外の場合は、代わりにelse文を実行し、いずれかの電子メールを受け取りませんメールを送信関数を呼び出す何か... –

関連する問題