jueves, 12 de mayo de 2016

 

como enviar correo ..asp net desarrollado en visual estudio2015



En este articulo desarrollaremos una aplicación de como enviar un correo
Como se muestra  en el siguiente imagen


























Código HTML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Emvio_correo.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> mi Aplicacion en ASP Envio de correo </title>
    <style type="text/css">
        #form1
        {
            height: 301px;
            width: 457px;
        }
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 46px;
        }
        .auto-style3 {
            text-align: left;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <div class="auto-style3">
            <strong>Envio de Correo</strong><br />
   
        </div>
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">De:</td>
                <td>
                    <asp:TextBox ID="txtde" runat="server" Width="181px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">Para:</td>
                <td>
                    <asp:TextBox ID="txtpara" runat="server" TextMode="Email" Width="182px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">Asunto:</td>
                <td>
                    <asp:TextBox ID="txtasunto" runat="server" Width="181px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">Mensaje:</td>
                <td>
                    <input id="Hidden1" type="hidden" />
                    <input id="Hidden2" type="hidden" />
                    <asp:TextBox ID="lscuerpos" runat="server" Height="71px" TextMode="MultiLine" Width="168px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Enviar" />
                    <input id="Reset1" type="reset" value="reset" /></td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td> </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

 Codigo del formulario
Primeramenta crearemos un modulo llamado útil.vb

Imports Microsoft.VisualBasic
Imports System.Net
Imports System.Net.Mail
Imports System.Text
Public Class util
    Public Shared Function Enviac(ByVal de As String, ByVal para As String, ByVal asunto As String, ByVal meNsaje As String)

        Dim msg As New System.Net.Mail.MailMessage
        msg.To.Add(para)
        msg.From = New MailAddress(de, "Curso asp", Encoding.UTF8)
        msg.Subject = asunto
        msg.SubjectEncoding = Encoding.UTF8
        msg.Body = meNsaje
        msg.BodyEncoding = Encoding.UTF8
        msg.IsBodyHtml = False

        Dim clientes As New SmtpClient
        clientes.Credentials = New NetworkCredential("cristiansinlimite@gmail.com", "vuelvemas")
        clientes.Host = "smtp.gmail.com"
        clientes.EnableSsl = True
        Try
            clientes.Send(msg)
            Return ("E-MAIL ENVIADO SATISFACTORIAMENTE")
            msg.Dispose()

        Catch ex As Exception
            Return ex.Message
        End Try

    End Function
End Class
Código  en el formulario para button enviar
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        util.Enviac(txtde.Text, txtpara.Text, txtasunto.Text, lscuerpos.text)


    End Sub

DESCARGAR APLICACIÓN EN EL SIGUIENTE LINK







Share:

0 comentarios:

Publicar un comentario

Dudas y sugerencias aqui