Email

Sending Email

sendmail.rb
1
#!/usr/bin/env ruby
2
# KING SABRI | @KINGSABRI
3
#
4
require 'net/smtp'
5
6
def send_mail(smtpsrv, username, password, frmemail, dstemail)
7
8
msg = "From: #{frmemail}\n"
9
msg += "To: #{dstemail}\n"
10
msg += "Date: #{date}\n"
11
msg += "Subject: Email Subject\n"
12
msg += "Content-type: text/html\n\n"
13
msg += "<strong>winter is coming<br>Hi Jon Snow, Please click to win!</strong>"
14
15
begin
16
Net::SMTP.start(smtpsrv, 25, 'localhost', username, password, :login) do |smtp|
17
smtp.send_message msg, frmemail, dstemail
18
end
19
puts "[+] Email has been sent successfully!"
20
rescue Exception => e
21
puts "[!] Failed to send the mail"
22
puts e
23
end
24
25
end
26
27
smtpsrv = ARGV[0]
28
username = "[email protected]"
29
password = "[email protected]"
30
frmemail = "[email protected]"
31
dstemail = "[email protected]"
32
33
smtpsrv = ARGV[0]
34
if smtpsrv.nil?
35
puts "[!] IP address Missing \nruby #{__FILE__}.rb [IP ADDRESS]\n\n"
36
exit 0
37
end
38
39
send_mail smtpsrv, username, password, frmemail, dstemail
Copied!

Reading Email

readmail.rb
1
#!/usr/bin/env ruby
2
# KING SABRI | @KINGSABRI
3
#
4
require 'net/imap'
5
6
host = ARGV[0]
7
if host.nil?
8
puts "[!] IP address Missing \nruby #{__FILE__}.rb [IP ADDRESS]\n\n"
9
exit 0
10
end
11
12
username = ARGV[1] || "[email protected]"
13
password = ARGV[2] || "[email protected]"
14
15
imap = Net::IMAP.new(host, 993, true, nil, false)
16
imap.login(username, password) # imap.authenticate('LOGIN', username, password)
17
imap.select('INBOX')
18
19
mail_ids = imap.search(['ALL'])
20
21
# Read all emails
22
mail_ids.each do |id|
23
envelope = imap.fetch(id, "ENVELOPE")[0].attr["ENVELOPE"]
24
puts "[+] Reading message, Subject: #{envelope.subject}"
25
puts imap.fetch(id,'BODY[TEXT]')[0].attr['BODY[TEXT]']
26
end
27
28
# Delete all emails
29
# mail_ids.each do |id|
30
# envelope = imap.fetch(id, "ENVELOPE")[0].attr["ENVELOPE"]
31
# puts "[+] Deleting message, Subject: #{envelope.subject}"
32
# imap.store(id, '+FLAGS', [:Deleted]) # Deletes forever No trash!
33
# end
34
35
imap.close
36
imap.logout
37
imap.disconnect
Copied!
Last modified 2yr ago