A sum for the $q$-expansion of Eisenstein series of weight $2.$ Let $N>1$ be a positive integer, let $(c_v,d_v)$ be positive integers such that $gcd(c_v,d_v,N)=1,$ and $0 \leq c_v \leq N-1.$ I have seen it claimed that  
$$\dfrac{1}{N^2}\sum_{c<0} \sum_{d \in \mathbb{Z}} (\dfrac{1}{(\frac{c_v\tau+d_v}{N}-c\tau-d)^2} - \dfrac{1}{(c\tau+d)^2}) $$ equals 
$$\dfrac{C_2}{N^2} \sum_{n=1}^\infty (\sum_{m | n \\n/m \equiv c_v \pmod N \\m>0 } m \mu_N^{d_vm})q^n_N -\dfrac{C_2}{N^2} \sum_{n=1}^\infty \sigma(n)q^n - (1-\delta(c_v)) \dfrac{C_2}{N^2}\sum_{m=1}^\infty \mu_N^{d_vm}mq_N^{c_vm}$$
where $\tau$ is in the upper half plane of $\mathbb{C},$ $q = e^{2\pi i  \tau},q_N = e^{2 \pi i \tau/N}, \mu_N = e^{2\pi i /N}$ and $C_2=(-2 \pi i)^2/2$ and $\sigma(n)$ is the divisor function and $\delta(c_v) =0$ if $c_v \neq 0,$ otherwise it is $1.$ I think this claim should follow from the identity 
$$\sum_{d \in \mathbb{Z}} \dfrac{1}{(\tau +d)^2} = C_2 \sum_{m=1}^\infty m q^m.$$ However, I do not see how we get the term $$ (1-\delta(c_v)) \dfrac{C_2}{N^2}\sum_{m=1}^\infty \mu_N^{d_vm}mq_N^{c_vm}.$$ This should be elementary but I do not see how it arises. Is the identity correct? If so, could someone explain how this term arises?
 A: Applying the identity you stated with $\tau$ replaced by $\frac{(c_v - Nc)\tau + d_v}{N}$ for $c < 0$ gives
\begin{equation*}
\begin{aligned}
 \sum_{d \in \mathbb{Z}} \frac{1}{\left( \frac{(c_v - Nc)\tau + d_v}{N} + d\right)^2} &= C_2\sum_{m=1}^{\infty}mq^{m\left(\frac{(c_v - Nc)\tau + d_v}{N}\right)} \\&= C_2\sum_{m=1}^{\infty}m\mu_N^{md_v}q_N^{m(c_v - Nc)\tau},
\end{aligned}
\end{equation*}
Note that $\frac{c_v\tau + d_v}{N} - c\tau + d = \frac{(c_v - Nc)\tau}{N} + d$, so summing the above over all $c < 0$ gives
$$\frac{1}{N^2}\sum_{c < 0} \sum_{d \in \mathbb{Z}} \frac{1}{\left(\frac{c_v\tau + d_v}{N} - c\tau + d\right)^2} = \frac{C_2}{N^2}\sum_{c < 0}\sum_{m=1}^{\infty}m\mu_N^{md_v}q_N^{m(c_v - Nc)\tau}.$$
Now we want to combine like powers of $q_N$. If $c_v = 0$, then as $c$ runs through the negative integers, $c_v - Nc$ runs through all positive integers which are congruent to $c_v \pmod N$. But if $c_v \neq 0$, then $c_v - Nc$ misses the positive integer $c_v$. This is why the mysterious last term you asked about arises. We have
$$\frac{C_2}{N^2}\sum_{c < 0}\sum_{m=1}^{\infty}m\mu_N^{md_v}q_N^{m(c_v - Nc)\tau} = \frac{C_2}{N^2}\sum_{n=1}^{\infty} \sum_{\substack{m \mid n \\ \frac{n}{m} \equiv c_v \\ m > 0}}m\mu_N^{d_vm}q_N^n - (1 - \delta(c_v))\sum_{m=1}^{\infty}m\mu_N^{md_v}q_N^{mc_v},$$
since in the first sum on the right-hand side $n$ runs through all positive integers which have a divisor congruent to $c_v$, while the second sum subtracts off the terms where said divisor is actually equal to $c_v$ (these terms do not appear on the left-hand side if $c_v \neq 0$).
