SendHTMLEmail: Difference between revisions
m (2 revisions imported) |
(No difference)
|
Latest revision as of 15:37, 6 April 2016
If you are running RT 3.8.2, please see docs/templates.pod in the extracted distribution for RT's support for HTML mail. You can also read that document in subversion(http://github.com/bestpractical/rt/blob/3.8-trunk/docs/templates.pod#Special_Headers)
This is a modification of RT::Action::SendEmail, which it will allow to RT to send mails not only with Content-Type: text/plain.
How is it working???
When you are editing a template, if you want that the outgoing mails using that template have other "Content-Type", you should add at the beginning of the template the mail header, and RT will care about the new value of the content-type.
For example: If we want to send outgoing html mails, you should add to the template the following sentence:
Content-Type: text/html
The patch has been developed for RT 3.6.4, so please take care if you are going to run it over other version of RT.
--- lib/RT/Action/SendEmail.pm 2007-05-25 22:16:34.000000000 +0200 +++ lib/RT/Action/SendEmail.pm 2008-02-04 18:08:58.000000000 +0100 @@ -155,8 +155,13 @@
# We should never have to set the MIME-Version header $self->SetHeader( 'MIME-Version', '1.0' );
- # try to convert message body from utf-8 to $RT::EmailOutputEncoding - $self->SetHeader( 'Content-Type', 'text/plain; charset="utf-8"' ); + # try to convert message body from utf-8 to $RT::EmailOutputEncoding + my $ContentType = $self->GetContentType(); + if (defined $ContentType) { + $self->SetHeader( 'Content-Type',$ContentType.'; charset="utf-8"' ); + } else { + $self->SetHeader( 'Content-Type', 'text/plain; charset="utf-8"' ); + }
# fsck.com #5959: Since RT sends 8bit mail, we should say so. $self->SetHeader( 'Content-Transfer-Encoding','8bit');
@@ -164,8 +169,11 @@
RT::I18N::SetMIMEEntityToEncoding( $MIMEObj, $RT::EmailOutputEncoding, 'mime_words_ok' );
- $self->SetHeader( 'Content-Type', 'text/plain; charset="' . $RT::EmailOutputEncoding . '"' ); - + if ($ContentType) { + $self->SetHeader( 'Content-Type',$ContentType.'; charset="' . $RT::EmailOutputEncoding . '"' ); + } else { + $self->SetHeader( 'Content-Type', 'text/plain; charset="' . $RT::EmailOutputEncoding . '"' ); + }
# Build up a MIME::Entity that looks like the original message. $self->AddAttachments() if ( $MIMEObj->head->get('RT-Attach-Message') );
@@ -722,6 +730,30 @@
# }}}
+# {{{ sub GetContentType + +=head2 GetContentType + +This routine sets the subject. it does not add the rt tag. that gets done elsewhere +If $self->{'Subject'} is already defined, it uses that. otherwise, it tries to get +the transaction's subject. + +=cut + +sub GetContentType { + my $self = shift; + my $subject; + + my $message = $self->TransactionObj->Attachments; + if ( $self->TemplateObj->MIMEObj->head->get('Content-Type') ) { + my $value = $self->TemplateObj->MIMEObj->head->get('Content-Type'); + chop($value); + return $value ; + } + return undef; +} + +# }}}
# {{{ sub SetSubject
]
Later Versions
I was not able to get this working under 3.8.1 with the above method. Instead I made changes to lib/RT/Template_Overlay . Here are the changes: Comment this passage on line 322:
if (defined $mime_type and $mime_type eq 'text/html') { $self->_DowngradeFromHTML(@_); }
On line 456 change the mime type from text/plain to text/html:
$new_entity->head->mime_attr( "Content-Type" => 'text/html' );
Note that this doesn't really preserve flexibility in what format you're sending your messages in. There is almost certainly a better way to do this.
One other comment: Anything submitted from the web interface is going to be stripped of certain tags. If you want to change this, and understand the security implications thereof, you can configure the scrubber in /html/Elements/ScrubHTML .