Class: CircularMail::PostMaster
- Inherits:
-
Object
- Object
- CircularMail::PostMaster
- Defined in:
- lib/circular-mail.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#mail_per_dispatch ⇒ Object
Returns the value of attribute mail_per_dispatch.
-
#message_body ⇒ Object
Returns the value of attribute message_body.
-
#message_character_set ⇒ Object
Returns the value of attribute message_character_set.
-
#message_format ⇒ Object
Returns the value of attribute message_format.
-
#message_subject ⇒ Object
Returns the value of attribute message_subject.
-
#recipients ⇒ Object
readonly
Returns the value of attribute recipients.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#sender_email ⇒ Object
Returns the value of attribute sender_email.
-
#smtp_server ⇒ Object
Returns the value of attribute smtp_server.
-
#smtp_server_authentication ⇒ Object
Returns the value of attribute smtp_server_authentication.
-
#smtp_server_password ⇒ Object
Returns the value of attribute smtp_server_password.
-
#smtp_server_port ⇒ Object
Returns the value of attribute smtp_server_port.
-
#smtp_server_username ⇒ Object
Returns the value of attribute smtp_server_username.
-
#wait_after_dispatch ⇒ Object
Returns the value of attribute wait_after_dispatch.
Instance Method Summary collapse
- #add_attachment(filename) ⇒ Object
- #add_recipient(*args) ⇒ Object
- #load_from_marshal(filename) ⇒ Object
- #load_from_yaml(filename) ⇒ Object
- #remove_attachment(filename) ⇒ Object
- #remove_recipient(email) ⇒ Object
- #save_as_marshal(filename) ⇒ Object
- #save_as_yaml(filename) ⇒ Object
-
#send ⇒ Object
(also: #send_all)
Start sending to all recipients using the standard process.
-
#send_to(email) ⇒ Object
Send the message to a single recipient Useful if a recipient is complaining that he did not get the message, due to a spam filter or accidentally deleted the email.
- #set_message(format, subject, message) ⇒ Object
- #set_message_variable(*args) ⇒ Object (also: #set_message_variables)
- #set_smtp_server(server_and_port, username, password, auth_type) ⇒ Object
- #smtp_authentication=(auth_type) ⇒ Object
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
50 51 52 |
# File 'lib/circular-mail.rb', line 50 def end |
#mail_per_dispatch ⇒ Object
Returns the value of attribute mail_per_dispatch.
52 53 54 |
# File 'lib/circular-mail.rb', line 52 def mail_per_dispatch @mail_per_dispatch end |
#message_body ⇒ Object
Returns the value of attribute message_body.
48 49 50 |
# File 'lib/circular-mail.rb', line 48 def end |
#message_character_set ⇒ Object
Returns the value of attribute message_character_set.
47 48 49 |
# File 'lib/circular-mail.rb', line 47 def end |
#message_format ⇒ Object
Returns the value of attribute message_format.
46 47 48 |
# File 'lib/circular-mail.rb', line 46 def end |
#message_subject ⇒ Object
Returns the value of attribute message_subject.
49 50 51 |
# File 'lib/circular-mail.rb', line 49 def end |
#recipients ⇒ Object (readonly)
Returns the value of attribute recipients.
51 52 53 |
# File 'lib/circular-mail.rb', line 51 def recipients @recipients end |
#sender ⇒ Object
Returns the value of attribute sender.
54 55 56 |
# File 'lib/circular-mail.rb', line 54 def sender @sender end |
#sender_email ⇒ Object
Returns the value of attribute sender_email.
55 56 57 |
# File 'lib/circular-mail.rb', line 55 def sender_email @sender_email end |
#smtp_server ⇒ Object
Returns the value of attribute smtp_server.
41 42 43 |
# File 'lib/circular-mail.rb', line 41 def smtp_server @smtp_server end |
#smtp_server_authentication ⇒ Object
Returns the value of attribute smtp_server_authentication.
45 46 47 |
# File 'lib/circular-mail.rb', line 45 def smtp_server_authentication @smtp_server_authentication end |
#smtp_server_password ⇒ Object
Returns the value of attribute smtp_server_password.
44 45 46 |
# File 'lib/circular-mail.rb', line 44 def smtp_server_password @smtp_server_password end |
#smtp_server_port ⇒ Object
Returns the value of attribute smtp_server_port.
42 43 44 |
# File 'lib/circular-mail.rb', line 42 def smtp_server_port @smtp_server_port end |
#smtp_server_username ⇒ Object
Returns the value of attribute smtp_server_username.
43 44 45 |
# File 'lib/circular-mail.rb', line 43 def smtp_server_username @smtp_server_username end |
#wait_after_dispatch ⇒ Object
Returns the value of attribute wait_after_dispatch.
53 54 55 |
# File 'lib/circular-mail.rb', line 53 def wait_after_dispatch @wait_after_dispatch end |
Instance Method Details
#add_attachment(filename) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/circular-mail.rb', line 183 def (filename) if .include?(filename) CircularMail::die "Attachment '#{filename}' already added!" if CircularMail::config('strictness') else CircularMail::die "Attachment file '#{filename}' does not exists!" if CircularMail::config('strictness') && !File.exists?(filename) << filename end end |
#add_recipient(*args) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/circular-mail.rb', line 144 def add_recipient(*args) if CircularMail::config('strictness') CircularMail::die "Email address '#{args[0]}' already added to recipients list!" if @recipients.include?(args[0]) CircularMail::die "Email address '#{args[0]}' is invalid!" if CircularMail::config('email_validation').match(args[0]).nil? && CircularMail::config('email_group_validation').match(args[0]).nil? end = [] if args.length > 1 (2..args.length).each { |var| << args[var - 1] } end @recipients << {args[0] => } end |
#load_from_marshal(filename) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/circular-mail.rb', line 297 def load_from_marshal(filename) if File.exists?(filename) o = File.open(filename, 'rb') {|f| m = Marshal::load(f)} @smtp_server = o.smtp_server @smtp_server_port = o.smtp_server_port @smtp_server_username = o.smtp_server_username @smtp_server_password = o.smtp_server_password @smtp_server_authentication = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password @recipients = o.smtp_server_password @mail_per_dispatch = o.smtp_server_password @wait_after_dispatch = o.smtp_server_password @sender = o.smtp_server_password @sender_email = o.smtp_server_password elsif CircularMail::config('strictness') CircularMail::die "Cannot load object because file '#{filename}' does not exists!" end end |
#load_from_yaml(filename) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/circular-mail.rb', line 274 def load_from_yaml(filename) if File.exists?(filename) o = YAML.load(File.read(filename)) @smtp_server = o.smtp_server @smtp_server_port = o.smtp_server_port @smtp_server_username = o.smtp_server_username @smtp_server_password = o.smtp_server_password @smtp_server_authentication = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password = o.smtp_server_password @recipients = o.smtp_server_password @mail_per_dispatch = o.smtp_server_password @wait_after_dispatch = o.smtp_server_password @sender = o.smtp_server_password @sender_email = o.smtp_server_password elsif CircularMail::config('strictness') CircularMail::die "Cannot load object because file '#{filename}' does not exists!" end end |
#remove_attachment(filename) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/circular-mail.rb', line 192 def (filename) if .include?(filename) .keep_if { |file| file != filename} elsif CircularMail::config('strictness') CircularMail::die "Attachment list does not contain file '#{filename}' !" end end |
#remove_recipient(email) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/circular-mail.rb', line 158 def remove_recipient(email) if @recipients.include?(email) @recipients.keep_if { |address| address != email} elsif CircularMail::config('strictness') CircularMail::die "Recipient list does not contain email address '#{email}' !" end end |
#save_as_marshal(filename) ⇒ Object
268 269 270 271 272 |
# File 'lib/circular-mail.rb', line 268 def save_as_marshal(filename) CircularMail::die "Cannot save object because file '#{filename}' already exists!" if File.exists?(filename) && CircularMail::config('strictness') filename = Dir.getwd() + "/dump #{CircularMail.file_timestamp()}.marshal" unless File.exists?(filename) File.open(filename, 'w') { |f| f.write(Marshal.dump(self)) } end |
#save_as_yaml(filename) ⇒ Object
262 263 264 265 266 |
# File 'lib/circular-mail.rb', line 262 def save_as_yaml(filename) CircularMail::die "Cannot save object because file '#{filename}' already exists!" if File.exists?(filename) && CircularMail::config('strictness') filename = Dir.getwd() + "/dump #{CircularMail.file_timestamp()}.yaml" unless File.exists?(filename) File.open(filename, 'w') { |f| f.write(YAML.dump(self)) } end |
#send ⇒ Object Also known as: send_all
Start sending to all recipients using the standard process
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/circular-mail.rb', line 201 def send() self.save_as_yaml(Dir.getwd() + "/backup #{CircularMail.file_timestamp()}.yaml") if CircularMail::config('auto_backup_postmaster') = 0 = 0 Net::SMTP.start(@smtp_server, @smtp_server_port, 'localhost', @smtp_server_username, @smtp_server_password, @smtp_server_authentication) do |smtp| = 0 = "" @recipients.each { |recipient| += 1 to_email = "" recipient.each { |mail, vars| to_email = mail var_index = 0 = if vars.length > 0 vars.each { |var_value| var_index += 1 = .gsub("@#{var_index.to_s}@", var_value) } else = end } = CircularMail::Message.new(, , ) . = .header.add_field('From', "#{@sender}<#{@sender_email}>") .header.add_field('Sender', "#{@sender}<#{@sender_email}>") .header.add_field('Reply-To', @sender_email) .header.add_field('To', "<#{to_email}>") .header.add_field('Subject', @subject) .header.add_field('Comments', 'This email was generated and posted by the CircularMail ruby library. Author is not responsible for body content!') .header.add_field('Date', CircularMail::()) = Digest::MD5.hexdigest() .header.add_field('Message-ID', "<CircularMail@#{$message_id}>") = .get() smtp. , @sender_email, to_email += 1 += 1 if == @mail_per_dispatch sleep @wait_after_dispatch = 0 end } end return end |
#send_to(email) ⇒ Object
Send the message to a single recipient Useful if a recipient is complaining that he did not get the message, due to a spam filter or accidentally deleted the email
258 259 260 |
# File 'lib/circular-mail.rb', line 258 def send_to(email) end |
#set_message(format, subject, message) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/circular-mail.rb', line 100 def (format, subject, ) self. = format if File.exists?(.to_s) self. = File.read(.to_s) else self. = end @subject = subject end |
#set_message_variable(*args) ⇒ Object Also known as: set_message_variables
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/circular-mail.rb', line 166 def (*args) # This method will add the email to recipients list if it does not exists yet! unless @recipients.include?(args[0]) #TODO: fix me! Need to look for email address INSIDE hash! add_recipient(*args) else # Ok, email exists lets override whatever variables it has = [] if args.length > 1 (2..args.length).each { |var| << args[var - 1] } end @recipients[@recipients.index(args[0])] = end end |
#set_smtp_server(server_and_port, username, password, auth_type) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/circular-mail.rb', line 92 def set_smtp_server(server_and_port, username, password, auth_type) self.smtp_server = server_and_port.to_s.split(":")[0] self.smtp_server_port = server_and_port.to_s.split(":")[1] self.smtp_server_username = username.to_s self.smtp_server_password = password.to_s self.smtp_server_authentication = auth_type.to_s end |
#smtp_authentication=(auth_type) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/circular-mail.rb', line 85 def smtp_authentication=(auth_type) if CircularMail::config('strictness') CircularMail::die "Authentication type '#{auth_type}' is not a valid option!" unless CircularMail::config('valid_authentications').include?(auth_type) end @smtp_server_authentication = auth_type end |