简体   繁体   中英

Styling body text in a href mailto link

I have an hyperlink which has a mailto link and I am specifying the subject and body text in the hyperlink itself. So when the user clicks on the hyperlink, his default email client application will be opened with the To, Subject and body text pre-populated in it.

I want to know how I can apply css formatting technique in the body text of it something like font names, font color etc.

Can anyone give me any idea on this?

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Unauthorized access</title> <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'> <!-- bootstrap 3.0.2 --> <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"> <!-- font Awesome --> <link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css" /> <!-- Theme style --> </head> <body class="skin-blue"> <!-- header logo: style can be found in header.less --> <div> <!-- Right side column. Contains the navbar and content of the page --> <aside class="right-side" style="margin-left:0"> <section class="content"> <div class="error-page" style="margin: 0"> <div class="error-content" style="width:100%"> <h3><i class="fa fa-warning text-yellow"></i> You are not authorized to view the content.</h3> <br> <p style="width:75%; text-align:center;margin-left:15%"> Please make sure you have the access to the server or contact support team at <a href="mailto:username@domain.com?subject=Unable&nbsp;to&nbsp;access&nbsp;server&body=Hi,%0D%0A%0D%0AMy&nbsp;user&nbsp;account&nbsp;does&nbsp;not&nbsp;have&nbsp;access&nbsp;for&nbsp;the&nbsp;server.%0D%0A%0D%0ARequest&nbsp;you&nbsp;to&nbsp;kindly&nbsp;provide&nbsp;access&nbsp;to&nbsp;server.">username@domain.com</a>. </p> </div><!-- /.error-content --> </div><!-- /.error-page --> </section><!-- /.content --> </aside><!-- /.right-side --> </div><!-- ./wrapper --> </body> </html> 

On clicking the email hyperlink, the below message will be shown in the email content.

样品

I want to apply css formatting to the content highlighted in the red box.

You can't change/modify CSS of a mail client through a <a href="mail to:mail@example.com"></a> .

They have their own CSS styles and this would be a security issue

Expanding on Dippas' answer...

According to the Mailto specification , you can add whatever arbitrary headers you want to your mailto link. This means you could add &Content-Type=text/html to the url to indicate it's an HTML message, in which case it should parse your HTML and CSS like a normal HTML email.

However the spec also states that the only headers that should be relied upon are the subject and body headers.

The creator of a mailto URL cannot expect the resolver of a URL to understand more than the "subject" and "body" headers. Clients that resolve mailto URLs into mail messages should be able to correctly create RFC 822-compliant mail messages using the "subject" and "body" headers.

In other words, you can try it, but don't expect it to work for everyone. If this is for public use, just forget about it, stick to plaintext.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM