Typesetting email address

You can use url package for this.

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[T1]{fontenc}
\DeclareUrlCommand\email{\urlstyle{rm}}

\begin{document}
\email{[email protected]}
\end{document}

enter image description here


The easiest way is to detokenize the text:

\documentclass{article}
\usepackage{color,hyperref}
    \catcode`\_=11\relax
    \newcommand\email[1]{\_email #1\q_nil}
    \def\_email#1@#2\q_nil{%
      \href{mailto:#1@#2}
        {{\emailfont\detokenize{#1}\emailampersat\detokenize{#2}}}%
    }
    \newcommand\emailfont{\sffamily}
    \newcommand\emailampersat{{\color{red}\small@}}
    \catcode`\_=8\relax   
\usepackage[T1]{fontenc}

\begin{document}
\email{[email protected]}
\end{document}

An expl3 implementation:

\documentclass{article}
%\usepackage[T1]{fontenc}
\usepackage{color,xparse,l3regex,hyperref}

\ExplSyntaxOn
\NewDocumentCommand{\email}{m}
 {
  \svend_email:n { #1 }
 }
\tl_new:N \l_svend_email_tl
\seq_new:N \l_svend_email_seq
\cs_generate_variant:Nn \seq_set_split:Nnn { NnV }
\cs_new_protected:Npn \svend_email:n #1
 {
  \tl_set:Nn \l_svend_email_tl { #1 }
  \regex_replace_all:nnN { \cD. } { \c{textunderscore} } \l_svend_email_tl
  \seq_set_split:NnV \l_svend_email_seq { @ } \l_svend_email_tl
  \href{ mailto:#1 }{ \emailfont \seq_use:Nn \l_svend_email_seq { \emailat } }
 }
\ExplSyntaxOff
\newcommand\emailfont{\sffamily}
\newcommand\emailat{{\color{red}\small @}}

\begin{document}
\email{[email protected]}
\email{[email protected]}
\end{document}

enter image description here