예제 #1
0
        private void EnviarEmail()
        {
            EnviarEmail enviarEmail = new EnviarEmail();

            IList <ItensCarrinho> itensCarrinhoAux = (List <ItensCarrinho>)Session["ItensPedido"];
            string html = string.Empty;

            html = @"<htmll>
                        <head></head>
                        <title></title>
                        <body>
                    <table class=""table table-hover"">
                        <thead>
                            <tr>
                                <th scope = ""col"">Produto</th>
                                <th scope = ""col"">Quantidade</th>
                                <th scope = ""col"">Valor</th>
                            </tr>
                        </thead>
                        <tbody>";

            string html2 = string.Empty;
            double valor = 0;


            foreach (var item in itensCarrinhoAux)
            {
                html2 = @"<tr>
                            <td>" + item.Produto + @"</td>" +
                        "<td>" + item.Quantidade + @" </td>" +
                        "<td>R$ " + item.Valor.ToString("N2") + @" </td>";

                valor = valor + item.Valor;
            }

            html = html + html2 + @"</tbody>
                                    </table>";
            html = html + @"<h2>O valor total do pedido é: R$ " + valor.ToString("N2") + @"</h2>" +
                   @"</body>
                                                                            </html>";


            try
            {
                Usuarios usu     = (Usuarios)Session["usuarioLogado"];
                string[] usuario = { usu.Email.ToString() };
                enviarEmail.Send(usuario, html);
            }
            catch (Exception ex)
            {
                throw;
            }
        }