# Exercise 7: Writing a Letter using the letter class (Solution)

This is a solution to the more adventurous part of Exercise 7. For the solution to the basic part, just add the sender details using the commands shown below.
\documentclass[12pt]{letter}

\usepackage[a4paper]{geometry}
\usepackage[british]{babel}

\usepackage{datatool}

% sender details
\location{Secret Lab of Experimental Stuff}
\telephone{0123456789}

\begin{document}

\newcommand*{\Id}{2}% customer id

\xDTLassignfirstmatch{people}{id}{\Id}{%
\Surname=surname,%
\Forenames=forenames,%
\Title=title,%
\Town=town,%
\County=county,%
\Postcode=postcode,%
\CountryCode=country%
}
\xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name}

\begin{letter}{ \DTLifnullorempty{\Title}{}{\Title\ }\Forenames\
\Surname\\%
\Town\\%
\DTLifnullorempty{\County}{}{\County\\}%
\Postcode\\\CountryName}

\opening{Dear \DTLifnullorempty{\Title}{\Forenames}{\Title} \Surname}

\thispagestyle{firstpage}
This is an imaginary letter.

This is the second paragraph of the letter.

\closing{Yours sincerely}

\ps PS: this is a postscript.

\encl{Photocopy of something interesting\\
Photocopy of something rather dull}

\cc{Prof Important Person\\Dr Bor Ing}
\end{letter}

\end{document}