connectseekers.com

Featured Articles

Decoration

All Stories

Monday, 29 August 2016

How to Send Mail in MVC6 Using C# Code With Attachment

8/29/2016 - By Pranav Singh 0

Friday, 26 August 2016

Send Mail In MVC5 and MVC6 In C# Using Gmail

This article will show you how you can send an email using gmail as smtp server in mvc5 and mvc6 using c#.net. This article you can use in MVC2, MVC3, MVC4, MVC5, MVC6.


So for this article first we will create a new  asp.net mvc application and add a controller and create the view for creating the form. This form will contain fields to provide information to send in email. Now add the below code in your view.

@model MvcApplication8.Models.CountryModel
@{
    ViewBag.Title = "Send Mail In MVC5 and MVC6 In C# Using Gmail";
}
@using (Html.BeginForm("Index", "Home"))
{
    <table width="100%" border="1">
        <tr>
            <td align="right" colspan="2" style="text-align: center"><strong>SEND EMAIL USING GMAIL ACCOUNT</strong></td>
        </tr>
        <tr>
            <td align="right">&nbsp;</td>
            <td align="left">
                @ViewBag.Message
            </td>
        </tr>
        <tr>
            <td align="right">To :</td>
            <td align="left">
                <input id="txttoaddress" name="ToEmailId" width="250px" />
            </td>
        </tr>
        <tr>
            <td align="right">Subject :</td>
            <td align="left">
                <input id="txtsubject" name="Subject" width="250px"></input>
            </td>
        </tr>
        <tr>
            <td align="right">Message Body :</td>
            <td align="left">
                <textarea rows="4" cols="50" name="Message" id="txtmessage"></textarea>
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <input type="submit" text="Send Message" />
            </td>
        </tr>
    </table>
}

In above code I have added some textbox and button control. Here we need to take care one thing about the name of the control. You must use a specific name of a control. So we use name of the control to access the value of control.

After this we will the below code to the controller.

using MvcApplication8.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication8.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(string ToEmailId, string Subject, string Message)
        {
            try
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(ToEmailId);
                mail.From = new MailAddress("yourgmailid@gmail.com");
                mail.Subject = Subject;
                string Body = Message;
                mail.Body = Body;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                //SMTP Server Address of gmail
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential("yourgmailid@gmail.com", "your password");
                // Smtp Email ID and Password For authentication
                smtp.EnableSsl = true;
                smtp.Send(mail);
                ViewBag.Message = "Your Message Send Successfully";
            }
            catch
            {
                ViewBag.Message = "Error............";
            }

            return View();
        }
    }
}

So in above code I have used the smtp of gmail for sending the email.  In above please check the parameter passed in the httppost method. Keep it same as the control names in your view.Now one this after execution if you are getting error message as shown below:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Then follow the below link to resolve the error.


Now we have done. Run the application to check the output.




Now check the received email


8/26/2016 - By Pranav Singh 0

Thursday, 25 August 2016

Send Mail In Asp.Net C# Using Gmail

8/25/2016 - By Pranav Singh 0

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Error message:

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

So what exactly this error and what is the solution. Her are few regions

1. When your server and the mail id are having different time zone

8/25/2016 - By Pranav Singh 0

Wednesday, 24 August 2016

Gmail Smtp Error : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Today while writing code to send the mail using Gmail as SMTP server. I got the below error message

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

So what exactly this error and what is the solution. Her are few regions

1. When your server and the mail id are having different time zone

8/24/2016 - By Pranav Singh 0

Wednesday, 17 August 2016

CheckBox Control Checked Uncheked By DataTable Value in Itemtemplate in Gridview in Asp.net Uisng C#

8/17/2016 - By Pranav Singh 0

Tuesday, 16 August 2016

Show Images in Gridview from Folder in Asp.net

8/16/2016 - By Pranav Singh 0

Sunday, 14 August 2016

MVC ListBoxFor Bind And Retrieve Selected Value Using C#.Net

8/14/2016 - By Pranav Singh 0

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top