Expanding the exponential function in a (classical) Fourier series

f[x_]=Exp[x]

Integrate[f[x]Cos[n x],{x,-Pi,Pi}]/Pi

Simplify[%,Assumptions->n∈Integers]

a[n_]=%

Integrate[f[x]Sin[n x],{x,-Pi,Pi}]/Pi

Simplify[%,Assumptions->n∈Integers]

b[n_]=%

a[1]

N[%]

b[1]

N[%]

The formula for a[n] above makes sense for n=0 but does not give the correct value since (Subscript[a, 0]) is computed with a different formula.  So, we overwrite the value a[0] using the following.

a[0]=Sinh[Pi]/Pi

Plot[{f[x],a[0]+a[1]Cos[x]+b[1]Sin[x]+a[2]Cos[2x]+b[2]Sin[2x]},{x,-Pi,Pi}]

Plot[{f[x],a[0]+Sum[a[n]Cos[n x]+b[n]Sin[n x],{n,1,4}]},{x,-Pi,Pi}]

Manipulate[
Plot[{f[x],a[0]+Sum[a[n]Cos[n x]+b[n]Sin[n x],{n,1,nmax}]},{x,-Pi,Pi},PlotRange->{-5,25}],
{nmax,1,100,1}]

framelist=Table[
Plot[{f[x],a[0]+Sum[a[n]Cos[n x]+b[n]Sin[n x],{n,1,nmax}]},{x,-Pi,Pi},PlotRange->{-5,25}],
{nmax,1,50,1}];

Export["FSAnimate.gif",framelist]