Module: ActionView::EncodedMailTo::MailToWithEncoding
- Defined in:
- lib/action_view/encoded_mail_to/mail_to_with_encoding.rb
Instance Method Summary collapse
-
#mail_to(email_address, name = nil, html_options = {}, &block) ⇒ Object
Creates a mailto link tag to the specified
email_address
, which is also used as the name of the link unlessname
is specified.
Instance Method Details
#mail_to(email_address, name = nil, html_options = {}, &block) ⇒ Object
Creates a mailto link tag to the specified email_address
, which is also used as the name of the link unless name
is specified. Additional HTML attributes for the link can be passed in html_options
.
mail_to
has several methods for hindering email harvesters and customizing the email itself by passing special keys to html_options
.
Options
-
:encode
- This key will accept the strings “javascript” or “hex”. Passing “javascript” will dynamically create and encode the mailto link then eval it into the DOM of the page. This method will not show the link on the page if the user has JavaScript disabled. Passing “hex” will hex encode theemail_address
before outputting the mailto link. -
:replace_at
- When the linkname
isn’t provided, theemail_address
is used for the link label. You can use this option to obfuscate theemail_address
by substituting the @ sign with the string given as the value. -
:replace_dot
- When the linkname
isn’t provided, theemail_address
is used for the link label. You can use this option to obfuscate theemail_address
by substituting the . in the email with the string given as the value. -
:subject
- Preset the subject line of the email. -
:body
- Preset the body of the email. -
:cc
- Carbon Copy additional recipients on the email. -
:bcc
- Blind Carbon Copy additional recipients on the email.
Examples
mail_to "[email protected]"
# => <a href="mailto:[email protected]">[email protected]</a>
mail_to "[email protected]", "My email", encode: "javascript"
# => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
mail_to "[email protected]", "My email", encode: "hex"
# => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
mail_to "[email protected]", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
# => <a href="mailto:[email protected]" class="email">me_at_domain_dot_com</a>
mail_to "[email protected]", "My email", cc: "[email protected]",
subject: "This is an example email"
# => <a href="mailto:[email protected][email protected]&subject=This%20is%20an%20example%20email">My email</a>
47 48 49 50 51 52 53 54 55 |
# File 'lib/action_view/encoded_mail_to/mail_to_with_encoding.rb', line 47 def mail_to(email_address, name = nil, = {}, &block) , name = name || {}, nil if block_given? && .blank? .stringify_keys! if %w[encode replace_at replace_dot].none?{ |option| .has_key? option } super email_address, name, , &block else _mail_to_with_encoding email_address, name, , &block end end |