Mail เป็นห้องสมุดอินเทอร์เน็ตสำหรับทับทิมที่ออกแบบมาเพื่อจัดการการสร้างอีเมลการแยกวิเคราะห์และการส่งในลักษณะที่เรียบง่ายและทับทิม
จุดประสงค์ของไลบรารีนี้คือการให้จุดเดียวในการเข้าถึงฟังก์ชั่นอีเมลทั้งหมดรวมถึงการส่งและรับอีเมล การดำเนินการประเภทเครือข่ายทั้งหมดจะทำผ่านวิธีพร็อกซีเพื่อทำ net :: smtp, net :: pop3 ฯลฯ
สร้างขึ้นจากประสบการณ์ของฉันกับ Tmail มันถูกออกแบบมาให้ใช้งานทับทิมบริสุทธิ์ที่ทำให้การสร้างส่งและแยกวิเคราะห์อีเมลเป็นเกมง่ายๆ
นอกจากนี้ยังได้รับการออกแบบมาจากพื้นดินเพื่อทำงานกับทับทิมรุ่นที่ทันสมัยกว่า ทับทิมที่ทันสมัยจัดการกับการเข้ารหัสข้อความที่น่าอัศจรรย์มากขึ้นกว่าเดิมดังนั้นคุณสมบัติเหล่านี้ได้รับประโยชน์อย่างเต็มที่จากในห้องสมุดนี้ทำให้เมลสามารถจัดการข้อความได้มากขึ้นกว่า TMAIL มากขึ้น
ในที่สุดจดหมายได้รับการออกแบบด้วยระบบเชิงวัตถุที่ง่ายมากซึ่งเปิดข้อความอีเมลที่คุณกำลังแยกวิเคราะห์ถ้าคุณรู้ว่าคุณกำลังทำอะไรอยู่คุณสามารถเล่นซอกับอีเมลทุกฉบับโดยตรง
ใช่คุณ! จดหมายถูกใช้ในแอพนับไม่ถ้วนโดยผู้คนทั่วโลก มันเป็นเช่นเดียวกับซอฟต์แวร์โอเพ่นซอร์สทั้งหมดซึ่งเป็นงานแห่งความรักที่เกิดจากเวลาว่างของเรา หากคุณต้องการพูดขอบคุณโปรดขุดและมีส่วนร่วมกับเรา! triage และแก้ไขปัญหา GitHub ปรับปรุงเอกสารของเราเพิ่มคุณสมบัติใหม่ - ให้คุณ! ขอบคุณสำหรับการขว้าง
จดหมายถูกทดสอบกับ:
เมื่อ Ruby รุ่นใหม่ได้รับการปล่อยตัวจดหมายจะเข้ากันได้กับการสนับสนุนสำหรับ "ตัวอย่าง" และ "การบำรุงรักษาปกติ" ทั้งหมด "การบำรุงรักษารักษาความปลอดภัย" และเวอร์ชัน "End of Life" ล่าสุดสองฉบับที่ระบุไว้ที่หน้าสาขาการบำรุงรักษาทับทิม คำขอดึงเพื่อช่วยในการเพิ่มการสนับสนุนสำหรับการเผยแพร่ตัวอย่างใหม่เป็นมากกว่ายินดีต้อนรับ
การกระทำของจดหมายทุกฉบับได้รับการทดสอบโดยการกระทำของ GitHub ในทุกรุ่นทับทิมที่ได้รับการสนับสนุน
หากคุณต้องการหารือเกี่ยวกับจดหมายกับบุคคลที่มีใจเดียวกันโปรดสมัครสมาชิกกลุ่ม Google
Mail เป็นไปตามมาตรฐาน RFC5322 และ RFC6532 ในขณะนี้นั่นคือสามารถแยกวิเคราะห์อีเมล US-ASCII และ UTF-8 และสร้างอีเมล US-ASCII มีไวยากรณ์อีเมลที่ล้าสมัยสองสามข้อที่มันจะมีปัญหา แต่มันก็ค่อนข้างแข็งแกร่งความหมายถ้าพบสิ่งที่ไม่เข้าใจว่ามันจะไม่ผิดพลาด แต่มันจะข้ามปัญหาและการแยกวิเคราะห์ ในกรณีของส่วนหัวมันไม่เข้าใจมันจะเริ่มต้นส่วนหัวเป็นฟิลด์ที่ไม่มีโครงสร้างเสริมและแยกวิเคราะห์ต่อไป
ซึ่งหมายความว่าจดหมายจะไม่ส่งข้อมูลของคุณ (ฉันคิดว่า)
คุณยังสามารถสร้างอีเมล MIME ได้ มีวิธีการของผู้ช่วยในการสร้างอีเมลหลายส่วน/สำรองสำหรับข้อความ/ธรรมดาและข้อความ/html (คู่ที่พบมากที่สุด) และคุณสามารถสร้างอีเมล MIME ประเภทอื่น ๆ ด้วยตนเอง
ถัดไปสิ่งที่ต้องทำ:
โดยทั่วไป ... เราทำ BDD ทางไปรษณีย์ ไม่มีวิธีการเขียนทางไปรษณีย์โดยไม่มีข้อมูลจำเพาะที่สอดคล้องกันหรือครอบคลุม เราคาดว่าจะมีความครอบคลุมขั้นต่ำ 100% ที่วัดโดย RCOV แม้ว่าสิ่งนี้จะไม่สมบูรณ์แบบไม่ว่าด้วยมาตรการใด ๆ แต่ก็ค่อนข้างดี นอกจากนี้การทดสอบการทำงานทั้งหมดจาก TMAIL จะต้องผ่านก่อนที่อัญมณีจะได้รับการปล่อยตัว
นอกจากนี้ยังหมายความว่าคุณมั่นใจได้ว่าจดหมายจะทำงานอย่างถูกต้อง
คุณสามารถเรียกใช้การทดสอบในเครื่องโดยเรียกใช้ bundle exec rspec
คุณสามารถเรียกใช้การทดสอบในรุ่นทับทิมที่รองรับทั้งหมดโดยใช้ ACT
ไม่มีการลบ API ภายในการเปิดตัวจุดเดียว การลบทั้งหมดที่จะเลิกใช้พร้อมคำเตือนอย่างน้อยหนึ่งจุดย่อยก่อนที่จะลบออก
นอกจากนี้วิธีการส่วนตัวหรือการป้องกันทั้งหมดที่จะประกาศเช่นนี้ - แม้ว่านี่จะยังคงเป็น I/P
การติดตั้งค่อนข้างง่ายฉันโฮสต์จดหมายบน Rubygems ดังนั้นคุณสามารถทำได้:
# gem install mail
หากคุณไม่ทราบการจัดการการเข้ารหัสในอีเมลนั้นไม่ตรงไปตรงมาอย่างที่คุณหวัง
ฉันพยายามทำให้ง่ายขึ้นบ้าง:
วัตถุทั้งหมดที่สามารถแสดงเป็นอีเมลมีวิธี #encoded
เข้ารหัสจะส่งคืนวัตถุเป็นสตริงที่สมบูรณ์พร้อมที่จะส่งในระบบเมลนั่นคือมันจะรวมฟิลด์ส่วนหัวและค่าและ CRLF ในตอนท้ายและห่อตามต้องการ
วัตถุทั้งหมดที่สามารถแสดงเป็นอีเมลมีวิธี #decoded
การถอดรหัสจะส่งคืน "ค่า" ของวัตถุเท่านั้นเป็นสตริง ซึ่งหมายความว่าจะไม่รวมฟิลด์ส่วนหัว (เช่น 'ถึง:' หรือ 'หัวเรื่อง:')
โดยค่าเริ่มต้นการโทร #to_s
บนวัตถุคอนเทนเนอร์จะเรียกวิธีการเข้ารหัสในขณะที่ #to_s
บนวัตถุฟิลด์จะเรียกวิธีการถอดรหัส ดังนั้นการโทร #to_s
บนวัตถุเมลจะส่งคืนอีเมลทั้งหมดที่เข้ารหัสพร้อมที่จะส่งในขณะที่โทร #to_s
บนฟิลด์ From หรือร่างกายจะส่งคืนค่าที่ถอดรหัสของวัตถุ วัตถุส่วนหัวของเมลถือเป็นคอนเทนเนอร์ หากคุณมีข้อสงสัยให้โทร #encoded
หรือ #decoded
อย่างชัดเจนสิ่งนี้ปลอดภัยกว่าถ้าคุณไม่แน่ใจ
ฟิลด์ที่มีโครงสร้างที่มีค่าพารามิเตอร์ที่สามารถเข้ารหัส (เช่นเนื้อหาประเภทเนื้อหา) จะให้ค่าพารามิเตอร์ที่ถอดรหัสเมื่อคุณเรียกชื่อพารามิเตอร์เป็นวิธีการกับวัตถุ
ฟิลด์ที่มีโครงสร้างที่มีค่าพารามิเตอร์ที่สามารถเข้ารหัส (เช่นเนื้อหาประเภทเนื้อหา) จะให้ค่าพารามิเตอร์ที่เข้ารหัสเมื่อคุณเรียกชื่อพารามิเตอร์ผ่านการเรียกเมธอดพารามิเตอร์ object.parameters['<parameter_name>']
กรุณาทำ! การมีส่วนร่วมเป็นเรื่องง่ายทางไปรษณีย์ โปรดอ่านเอกสาร MD ที่มีส่วนร่วมสำหรับข้อมูลเพิ่มเติม
ฟังก์ชั่นจดหมายที่สำคัญทั้งหมดควรจะสามารถเกิดขึ้นได้จากโมดูลเมล ดังนั้นคุณควรจะสามารถ require 'mail'
เพื่อเริ่มต้นได้
mail
ได้รับการบันทึกไว้อย่างดีในรหัสทับทิม คุณสามารถค้นหาได้เช่นที่ rubydoc.info
mail = Mail . new do
from '[email protected]'
to '[email protected]'
subject 'This is a test email'
body File . read ( 'body.txt' )
end
mail . to_s #=> "From: [email protected]: you@...
mail = Mail . new do
body File . read ( 'body.txt' )
end
mail [ 'from' ] = '[email protected]'
mail [ :to ] = '[email protected]'
mail . subject = 'This is a test email'
mail . header [ 'X-Custom-Header' ] = 'custom value'
mail . to_s #=> "From: [email protected]: you@...
mail = Mail . new do
to '[email protected]'
body 'Some simple body'
end
mail . to_s =~ /Message - ID: <[ d w _]+@.+.mail/ #=> 27
เมลจะเพิ่มฟิลด์ Message-ID โดยอัตโนมัติหากหายไปและให้ข้อความแบบสุ่มแบบสุ่มตามบรรทัดของ:
mail = Mail . new do
to '[email protected]'
message_id '<[email protected]>'
body 'Some simple body'
end
mail . to_s =~ /Message - ID: <[email protected]>/ #=> 27
จดหมายจะใช้ Message_id ที่คุณกำหนดไว้ให้ไว้วางใจว่าคุณรู้ว่าคุณกำลังทำอะไรอยู่
ค่าเริ่มต้นอีเมลไปที่การส่งผ่าน SMTP ไปยังพอร์ตโฮสต์ท้องถิ่น 25 หากคุณมี sendmail หรือ postfix daemon ที่ทำงานบนพอร์ตนี้การส่งอีเมลเป็นเรื่องง่ายเหมือน:
Mail . deliver do
from '[email protected]'
to '[email protected]'
subject 'Here is the image you wanted'
body File . read ( 'body.txt' )
add_file '/full/path/to/somefile.png'
end
หรือ
mail = Mail . new do
from '[email protected]'
to '[email protected]'
subject 'Here is the image you wanted'
body File . read ( 'body.txt' )
add_file :filename => 'somefile.png' , :content => File . read ( '/somefile.png' )
end
mail . deliver!
การส่งผ่าน Sendmail สามารถทำได้เช่นนั้น:
mail = Mail . new do
from '[email protected]'
to '[email protected]'
subject 'Here is the image you wanted'
body File . read ( 'body.txt' )
add_file :filename => 'somefile.png' , :content => File . read ( '/somefile.png' )
end
mail . delivery_method :sendmail
mail . deliver
ส่งผ่าน SMTP (ตัวอย่างเช่น MailCatcher)
Mail . defaults do
delivery_method :smtp , address : "localhost" , port : 1025
end
Exim ต้องการผู้จัดการการจัดส่งของตัวเองและสามารถใช้งานได้เช่นนั้น:
mail . delivery_method :exim , :location => "/usr/bin/exim"
mail . deliver
จดหมายอาจเป็น "ส่ง" ไปยัง LogFile เช่นกันสำหรับการพัฒนาและการทดสอบ:
# Delivers by logging the encoded message to $stdout
mail . delivery_method :logger
# Delivers to an existing logger at :debug severity
mail . delivery_method :logger , logger : other_logger , severity : :debug
คุณสามารถกำหนดค่าอีเมลเพื่อรับอีเมลโดยใช้ retriever_method
ภายใน Mail.defaults
:
# e.g. POP3
Mail . defaults do
retriever_method :pop3 , :address => "pop.gmail.com" ,
:port => 995 ,
:user_name => '<username>' ,
:password => '<password>' ,
:enable_ssl => true
end
# IMAP
Mail . defaults do
retriever_method :imap , :address => "imap.mailbox.org" ,
:port => 993 ,
:user_name => '<username>' ,
:password => '<password>' ,
:enable_ssl => true
end
คุณสามารถเข้าถึงอีเมลที่เข้ามาได้หลายวิธี
อีเมลล่าสุด:
Mail . all #=> Returns an array of all emails
Mail . first #=> Returns the first unread email
Mail . last #=> Returns the last unread email
10 อีเมลแรกที่เรียงลำดับตามวันที่ตามลำดับจากน้อยไปมาก:
emails = Mail . find ( :what => :first , :count => 10 , :order => :asc )
emails . length #=> 10
หรือแม้แต่อีเมลทั้งหมด:
emails = Mail . all
emails . length #=> LOTS!
mail = Mail . read ( '/path/to/message.eml' )
mail . envelope_from #=> '[email protected]'
mail . from . addresses #=> ['[email protected]', '[email protected]']
mail . sender . address #=> '[email protected]'
mail . to #=> '[email protected]'
mail . cc #=> '[email protected]'
mail . subject #=> "This is the subject"
mail . date . to_s #=> '21 Nov 1997 09:55:06 -0600'
mail . message_id #=> '<[email protected]>'
mail . decoded #=> 'This is the body of the email...
มีวิธีอื่น ๆ อีกมากมาย
mail = Mail . read ( 'multipart_email' )
mail . multipart? #=> true
mail . parts . length #=> 2
mail . body . preamble #=> "Text before the first part"
mail . body . epilogue #=> "Text after the last part"
mail . parts . map { | p | p . content_type } #=> ['text/plain', 'application/pdf']
mail . parts . map { | p | p . class } #=> [Mail::Message, Mail::Message]
mail . parts [ 0 ] . content_type_parameters #=> {'charset' => 'ISO-8859-1'}
mail . parts [ 1 ] . content_type_parameters #=> {'name' => 'my.pdf'}
จดหมายสร้างต้นไม้ชิ้นส่วน แต่ละข้อความมีชิ้นส่วนมากมายหรือไม่มีเลย แต่ละส่วนเป็นข้อความอื่นที่สามารถมีชิ้นส่วนได้มากมายหรือไม่มีเลย
ข้อความจะมีชิ้นส่วนเฉพาะในกรณีที่เป็นประเภทเนื้อหาแบบหลายส่วน/ผสมหรือหลายส่วน/ที่เกี่ยวข้องและมีขอบเขตที่กำหนดไว้
mail . attachments . each do | attachment |
# Attachments is an AttachmentsList object containing a
# number of Part objects
if ( attachment . content_type . start_with? ( 'image/' ) )
# extracting images for example...
filename = attachment . filename
begin
File . open ( images_dir + filename , "w+b" , 0644 ) { | f | f . write attachment . decoded }
rescue => e
puts "Unable to save data for #{ filename } because #{ e . message } "
end
end
end
Mail ทำให้สมมติฐานพื้นฐานบางอย่างและทำให้การทำสิ่งทั่วไปง่ายที่สุดเท่าที่จะเป็นไปได้ .... (ขอมากจากห้องสมุดจดหมาย)
mail = Mail . deliver do
part :content_type => "multipart/mixed" do | p1 |
p1 . part :content_type => "multipart/related" do | p2 |
p2 . part :content_type => "multipart/alternative" ,
:content_disposition => "inline" do | p3 |
p3 . part :content_type => "text/plain; charset=utf-8" ,
:body => "Here is the attachment you wanted n "
p3 . part :content_type => "text/html; charset=utf-8" ,
:body => "<h1>Funky Title</h1><p>Here is the attachment you wanted</p> n "
end
end
add_file '/path/to/myfile.pdf'
end
from "Mikel Lindsaar <[email protected]>"
to "[email protected]"
subject "First multipart email sent with Mail"
end
จดหมายจากนั้นส่งอีเมลที่ส่วนท้ายของบล็อกและส่งคืนอีเมลผลลัพธ์ :: ข้อความซึ่งคุณสามารถตรวจสอบได้ว่าคุณต้องการ ...
puts mail.to_s #=>
Date: Tue, 26 Apr 2022 20:12:07 +0200
From: Mikel Lindsaar <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
Subject: First multipart email sent with Mail
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="--==_mimepart_626835f733867_10873fdfa3c2ffd494636";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
Content-Type: multipart/mixed;
boundary="--==_mimepart_626835f73382a_10873fdfa3c2ffd494518";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518
Content-Type: multipart/related;
boundary="--==_mimepart_626835f7337f5_10873fdfa3c2ffd494438";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438
Content-Type: multipart/alternative;
boundary="--==_mimepart_626835f733702_10873fdfa3c2ffd494376";
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-ID: <[email protected]>
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: 7bit
Here is the attachment you wanted
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: 7bit
<h1>Funky Title</h1><p>Here is the attachment you wanted</p>
----==_mimepart_626835f733702_10873fdfa3c2ffd494376--
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438--
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518--
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
Content-Type: text/plain;
charset=UTF-8;
filename=myfile.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=myfile.txt
Content-ID: <6
[email protected]>
Hallo,
Test
End
----==_mimepart_626835f733867_10873fdfa3c2ffd494636--
จดหมายแทรกการเข้ารหัสการถ่ายโอนเนื้อหาเวอร์ชัน MIME เนื้อหา ID และจัดการประเภทเนื้อหาและขอบเขต
จดหมายถือว่าหากข้อความของคุณในร่างกายเป็นเพียง US-ASCII เท่านั้นการเข้ารหัสการถ่ายโอนของคุณคือ 7 บิตและเป็นข้อความ/ธรรมดา คุณสามารถแทนที่สิ่งนี้ได้โดยการประกาศอย่างชัดเจน
คุณไม่จำเป็นต้องใช้บล็อกกับข้อความและส่วน HTML ที่รวมอยู่ด้วยคุณสามารถทำได้ อย่างไรก็ตามคุณต้องเพิ่ม Mail :: Parts ไปยังอีเมลไม่ใช่ Mail :: Messages
mail = Mail . new do
to '[email protected]'
from 'Mikel Lindsaar <[email protected]>'
subject 'First multipart email sent with Mail'
end
text_part = Mail :: Part . new do
body 'This is plain text'
end
html_part = Mail :: Part . new do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
end
mail . text_part = text_part
mail . html_part = html_part
ผลลัพธ์ในอีเมลเดียวกับที่ทำโดยใช้แบบฟอร์มบล็อก
@mail = Mail . read ( '/path/to/bounce_message.eml' )
@mail . bounced? #=> true
@mail . final_recipient #=> rfc822;[email protected]
@mail . action #=> failed
@mail . error_status #=> 5.5.0
@mail . diagnostic_code #=> smtp;550 Requested action not taken: mailbox unavailable
@mail . retryable? #=> false
คุณสามารถอ่านไฟล์ออกจากเส้นทางที่แน่นอนเมลจะพยายามเดา mime_type และจะเข้ารหัสไฟล์ใน Base64 สำหรับคุณ
@mail = Mail . new
@mail . add_file ( "/path/to/file.jpg" )
@mail . parts . first . attachment? #=> true
@mail . parts . first . content_transfer_encoding . to_s #=> 'base64'
@mail . attachments . first . mime_type #=> 'image/jpg'
@mail . attachments . first . filename #=> 'file.jpg'
@mail . attachments . first . decoded == File . read ( '/path/to/file.jpg' ) #=> true
หรือคุณสามารถส่งผ่าน file_data และตั้งชื่อไฟล์อีกครั้งอีเมลจะลองและเดา mime_type สำหรับคุณ
@mail = Mail . new
@mail . attachments [ 'myfile.pdf' ] = File . read ( 'path/to/myfile.pdf' )
@mail . parts . first . attachment? #=> true
@mail . attachments . first . mime_type #=> 'application/pdf'
@mail . attachments . first . decoded == File . read ( 'path/to/myfile.pdf' ) #=> true
นอกจากนี้คุณยังสามารถแทนที่ประเภทสื่อ MIME ที่เดาได้หากคุณรู้ดีกว่าเมล (ควรจะไม่ค่อยจำเป็น)
@mail = Mail . new
@mail . attachments [ 'myfile.pdf' ] = { :mime_type => 'application/x-pdf' ,
:content => File . read ( 'path/to/myfile.pdf' ) }
@mail . parts . first . mime_type #=> 'application/x-pdf'
แน่นอน ... จดหมายจะไปกลับไฟล์แนบเช่นกัน
@mail = Mail . new do
to '[email protected]'
from 'Mikel Lindsaar <[email protected]>'
subject 'First multipart email sent with Mail'
text_part do
body 'Here is the attachment you wanted'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>Funky Title</h1><p>Here is the attachment you wanted</p>'
end
add_file '/path/to/myfile.pdf'
end
@round_tripped_mail = Mail . new ( @mail . encoded )
@round_tripped_mail . attachments . length #=> 1
@round_tripped_mail . attachments . first . filename #=> 'myfile.pdf'
ดู "การทดสอบและการสกัดสิ่งที่แนบมา" ด้านบนสำหรับรายละเอียดเพิ่มเติม
หากจดหมายเป็นส่วนหนึ่งของระบบของคุณคุณจะต้องมีวิธีทดสอบโดยไม่ต้องส่งอีเมลจริง TestMailer สามารถทำสิ่งนี้ให้คุณได้
require 'mail'
=> true
Mail . defaults do
delivery_method :test
end
=> #<Mail::Configuration:0x19345a8 @delivery_method=Mail::TestMailer>
Mail :: TestMailer . deliveries
=> [ ]
Mail . deliver do
to '[email protected]'
from '[email protected]'
subject 'testing'
body 'hello'
end
=> #<Mail::Message:0x19284ec ...
Mail :: TestMailer . deliveries . length
=> 1
Mail :: TestMailer . deliveries . first
=> #<Mail::Message:0x19284ec ...
Mail :: TestMailer . deliveries . clear
=> [ ]
นอกจากนี้ยังมีชุดของการจับคู่ RSPEC ที่ถูกขโมย/ได้รับแรงบันดาลใจจาก ActionMailer Matchers (คุณจะต้องการตั้ง delivery_method
ดังกล่าวข้างต้นด้วย):
Mail . defaults do
delivery_method :test # in practice you'd do this in spec_helper.rb
end
RSpec . describe "sending an email" do
include Mail :: Matchers
before ( :each ) do
Mail :: TestMailer . deliveries . clear
Mail . deliver do
to [ '[email protected]' , '[email protected]' ]
from '[email protected]'
subject 'testing'
body 'hello'
end
end
it { is_expected . to have_sent_email } # passes if any email at all was sent
it { is_expected . to have_sent_email . from ( '[email protected]' ) }
it { is_expected . to have_sent_email . to ( '[email protected]' ) }
# can specify a list of recipients...
it { is_expected . to have_sent_email . to ( [ '[email protected]' , '[email protected]' ] ) }
# ...or chain recipients together
it { is_expected . to have_sent_email . to ( '[email protected]' ) . to ( '[email protected]' ) }
it { is_expected . to have_sent_email . with_subject ( 'testing' ) }
it { is_expected . to have_sent_email . with_body ( 'hello' ) }
# Can match subject or body with a regex
# (or anything that responds_to? :match)
it { is_expected . to have_sent_email . matching_subject ( /test(ing)?/ ) }
it { is_expected . to have_sent_email . matching_body ( /h(a|e)llo/ ) }
# Can chain together modifiers
# Note that apart from recipients, repeating a modifier overwrites old value.
it { is_expected . to have_sent_email . from ( '[email protected]' ) . to ( '[email protected]' ) . matching_body ( /hell/ )
# test for attachments
# ... by specific attachment
it { is_expected . to have_sent_email . with_attachments ( my_attachment ) }
# ... or any attachment
it { is_expected . to have_sent_email . with_attachments ( any_attachment ) }
# ... or attachment with filename
it { is_expected . to have_sent_email . with_attachments ( an_attachment_with_filename ( 'file.txt' ) ) }
# ... or attachment with mime_type
it { is_expected . to have_sent_email . with_attachments ( an_attachment_with_mime_type ( 'application/pdf' ) ) }
# ... by array of attachments
it { is_expected . to have_sent_email . with_attachments ( [ my_attachment1 , my_attachment2 ] ) } #note that order is important
#... by presence
it { is_expected . to have_sent_email . with_any_attachments }
#... or by absence
it { is_expected . to have_sent_email . with_no_attachments }
end
ไฟล์ฟิกซ์เจอร์สเป็คในข้อมูลจำเพาะ/การติดตั้ง/อีเมล/FROM_TREC_2005 มาจากคลังข้อมูลสแปมสาธารณะ TREC 2005 พวกเขายังคงมีลิขสิทธิ์ภายใต้ข้อกำหนดของโครงการและข้อตกลงใบอนุญาต พวกเขาใช้ในโครงการนี้เพื่อตรวจสอบและอธิบายการพัฒนาของการใช้งานตัวแยกวิเคราะห์อีเมลนี้
http://plg.uwaterloo.ca/~gvcormac/treccorpus/
พวกเขาจะใช้ตามที่ได้รับอนุญาตโดย 'การใช้งานที่ได้รับอนุญาต, ข้อ 3':
"Small excerpts of the information may be displayed to others
or published in a scientific or technical context, solely for
the purpose of describing the research and development and
related issues."
-- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
(ใบอนุญาต MIT)
ลิขสิทธิ์ (c) 2009-2016 Mikel Lindsaar
ได้รับอนุญาตโดยไม่เสียค่าใช้จ่ายสำหรับบุคคลใด ๆ ที่ได้รับสำเนาซอฟต์แวร์นี้และไฟล์เอกสารที่เกี่ยวข้อง ('ซอฟต์แวร์') เพื่อจัดการในซอฟต์แวร์โดยไม่มีการ จำกัด รวมถึง แต่ไม่ จำกัด เฉพาะสิทธิ์ในการใช้คัดลอกแก้ไขผสาน เผยแพร่แจกจ่าย sublicense และ/หรือขายสำเนาของซอฟต์แวร์และอนุญาตให้บุคคลที่ซอฟต์แวร์ได้รับการตกแต่งให้ทำเช่นนั้นภายใต้เงื่อนไขดังต่อไปนี้:
ประกาศลิขสิทธิ์ข้างต้นและประกาศการอนุญาตนี้จะรวมอยู่ในสำเนาทั้งหมดหรือส่วนสำคัญของซอฟต์แวร์
ซอฟต์แวร์มีให้ 'ตามที่เป็นอยู่' โดยไม่มีการรับประกันใด ๆ ไม่ว่าโดยชัดแจ้งหรือโดยนัยรวมถึง แต่ไม่ จำกัด เพียงการรับประกันความสามารถในการค้าการออกกำลังกายเพื่อวัตถุประสงค์เฉพาะและการไม่เข้าร่วม ไม่ว่าในกรณีใดผู้เขียนหรือผู้ถือลิขสิทธิ์จะต้องรับผิดชอบต่อการเรียกร้องความเสียหายหรือความรับผิดอื่น ๆ ไม่ว่าจะเป็นการกระทำของสัญญาการละเมิดหรืออื่น ๆ ซอฟต์แวร์.