Sending emails using Part 77


Text version of the video


All ASP .NET Text Articles

All ASP .NET Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In the previous sessions of this video series, we have discussed about logging exceptions to database and to the windows eventviewer. In this session, sending an email to the development team or administrator along with logging exceptions.

To compose the email message, use MailMessage calss. To send the email use, SmtpClient class. both of these classes are present in System.Net.Mail namespace.

In this video we discussed about sending emails using gmail smtp server and credentials. In reality organisations have their own SMPT server. If you want to send emails using your own SMTP server, use the respective smtp server address and credentials.



  1. In localhost email sending is successful but my website hosting on GoDaddy then after email does not can I solve it?

  2. Hi kudvenkat,
    Do you have any video on how to retrieve email from a Yahoo, Gmail or free internet mail account using ASP.NET

    Really looking for something that will pull all the data for an email and insert it into a database table,
    including the unique email message ID, so I know not to read it again, or send an instruction back to the mail service to mark it as read and/or to move it in to a "READ" folder or delete the email.
    (the reason for not just use the mails status of "Read", is that someone could click on the mail message with in a mail client and mark it as read so it is never picked up by the ASP.NET application's polling retrieval routine {examples of polling techniques would also be appreciated})

  3. Hello sir can you help me please
    I want a code to send it massge to Emile or Mobail number
    Every 6 months

  4. I have one doubt I am fresher . please help Me sir..actually the developer kept all files which are notified in web on server isn't?..suppose in one website showing "click to download this file "….suppose the file is not present error message is shown to user and the exception message is stored in event viewer or db …am I correct?..but we are the developer…in your previous video u told the country file is deleted by someone….how could be it possible.. no one cannot access the web except developer….the user only make use of application.. how they able to delete a file inside of application?…

  5. Couldnot sent emailRequest for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Code error

  6. When I run this program, Google blocks the sign-in and I get this message: Are you the one who tried signing in?
    Google will continue to block sign-in attempts from the app you're using because it has known security problems or is out of date. You can continue to use this app by allowing access to less secure apps, but this may leave your account vulnerable.

    I don't want to change my account to allow less secure sign-in because that makes my account vulnerable.

    Hopefully you can update this tutorial to a more useful one. Thanks.

  7. Dear sir we use jio net as hotspot through my pc /laptop , we try to send mail outlook 2013 but we face this type of msg sending reported error (0x800CCC0D) msg reflected, we are requested to can you provide any solution for this type of msg , only this msg reflated jio net other internet service provider (ISP) smoothly mail send .

  8. System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    email is sending on local but the above error on hosting

  9. Is it possible to do smtpClient with Kerberos/ NTML / Negiotiate / Windows Authentication using the HttpContext User Identity?

  10. 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
    i got that error how can i over come it ??

  11. //use this code
    MailMessage mail = new MailMessage();

    mail.From = new MailAddres("mm");
    mail.Subject = "sub";

    mail.Body = "jjjj";

    mail.IsBodyHtml = true;

    SmtpClient smtp = new SmtpClient();
    smtp.Host = ""; //Or Your SMTP Server Address
    smtp.Credentials = new System.Net.NetworkCredential
    ("man", "man"); // **use valid credentials**
    smtp.Port = 587;
    //Or your Smtp Email ID and Password
    smtp.EnableSsl = true;
    catch (Exception ex)
    Response.Write("Exception in sendEmail:" + ex.Message);

  12. You are amizing persone i like your tutorial
    if some peroblem or error use this link and check on
    after this close the browser
    when i make this it work
    than you!

  13. please correct my code
    MailMessage msgobj = new MailMessage();
    SmtpClient serverobj = new SmtpClient();
    serverobj.Credentials = new NetworkCredential(TextBox1.Text, TextBox2.Text);
    serverobj.UseDefaultCredentials = false;
    serverobj.Host = "";
    serverobj.Port = 587;
    serverobj.EnableSsl = false;

    msgobj.From = new MailAddress(TextBox1.Text, "", System.Text.Encoding.UTF8);
    msgobj.Subject = TextBox4.Text;
    msgobj.Body = TextBox5.Text;
    msgobj.Attachments.Add(new Attachment(MapPath(Label1.Text)));
    msgobj.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    lblmsg.Text = "Email sent Successfully";

  14. hi kudvenkat sir , i am getting error when run the code "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. ga13sm11009493pac.47 – gsmtp"

  15. If anybody is unable to send email
    Login to your email then
    go to myacount security copy and paste below link in a new browser window

    at Connected apps & sites

    turn on "Allow Less Secure Apps"

    If anybody found alternative let me know

  16. Sir i have done exactly what you did and it is showing no error but i dont know why it is not generating any email in my Inbox….can you pzz suggest anything..Thank You.. 

  17. The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required……. Error is comming…. how to fix this….


Please enter your comment!
Please enter your name here