How to send a custom design email recipients in asp.net c#

In this article, we have design a mail with color full div , with image and a click event . many time we get emails with beautiful design then we think that you we can create email with asp.net c# . we can also get the same think with html template.But here I have used the html tags in c# page.




Design:-



Source Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Customemail.aspx.cs" Inherits="Customemail" %>

<!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 id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <br />
    <fieldset style="width: 400px;">
        <legend>Custom Email Design Example</legend>
        <table>
            <tr>
                <td>
                    Name
                </td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Email
                </td>
                <td>
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
            </tr>
           
            <tr>
                <td align="center" colspan="2">
                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click"
                        Font-Bold="True" Font-Size="Medium" Width="200px" />
                </td>
            </tr>
        </table>
    </fieldset>
    </form>
</body>
</html>


Code behind (C#):-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;

public partial class Customemail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        using (MailMessage mm = new MailMessage("sender@gmail.com", txtemail.Text))
        {

            mm.Subject = "Welcome To Code Solutions";

            string body = "<div style='background-color:#ba2323; ' align='center'>";
            body += "<p style='color:White; font-weight: bold;'>Hello  " + txtname.Text.Trim() + "</p>";
            body += "<br /> <p style='color:White;'>Thanks For visit our blog <p>";

            body += "<br/> <a style='display: block;height:70px;width: 250px;background: #34696f;border: 2px solid rgba(33, 68, 72, 0.59);color: rgba(0, 0, 0, 0.55);text-align: center;font: bold 1.2em/70px  Arial, Helvetica, Geneva, sans-serif;background: webkit-linear-gradient(top, #34696f, #2f5f63);background: -moz-linear-gradient(top, #34696f, #2f5f63); background: -o-linear-gradient(top, #34696f, #2f5f63);background: -ms-linear-gradient(top, #34696f, #2f5f63);background: linear-gradient(top, #34696f, #2f5f63); -webkit-border-radius: 50px;-khtml-border-radius: 50px;-moz-border-radius: 50px; border-radius: 50px;-webkit-box-shadow: 0 8px 0 #1b383b; -moz-box-shadow: 0 8px 0 #1b383b; box-shadow: 0 8px 0 #1b383b;  text-shadow: 0 2px 2px rgba(255, 255, 255, 0.2);' href = 'http://www.neerajcodesolutions.com/'>Click Here</a>";
            body += "<br /><p style='color:White;'> We sincerely hope you have a great time using our services.</p><p style='color:White;'> For any feedback please write to us at srinickraj@gmail.com</p> <br/>";

            body += "</div>";
            mm.Body = body;
            mm.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            NetworkCredential NetworkCred = new NetworkCredential("sender@gmail.com", "password");
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 587;
            smtp.Send(mm);
            Response.Write("<Script>alert('Thanks for posting your resume us,our team will be contact you as soon as possible')</Script>");
            // Clear the textbox values
            txtname.Text = "";
            txtemail.Text = "";
        }
    }
}



Out-Put:-


How to send a custom design email recipients in asp.net c# How to send a custom design email recipients in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 6:55:00 PM Rating: 5

1 comment:

Powered by Blogger.