Sending Email Through ASP.NET using C#

Sending Email Through ASP.NET using C#



The following Sample Code is the code which can be used to send mails through ASP.Net C#.... its a working code for me.....


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Calling the function SendMail
Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body"));
}

public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.server.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");

smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}

}





Thanks and Regards
Meetu Choudhary

Reference: http://aspnetbymeetu.blogspot.com/2009/03/sending-email-through-aspnet-using-c.html


Attachments

  • Email.aspx (21608-32324-Enquiry.aspx.txt)
  • Email.aspx.cs (21608-32325-Enquiry.aspx.cs.txt)
  • Comments

    Author: Narayanan Sukumaran03 Oct 2008 Member Level: Gold   Points : 1

    I have tried the above code, but i got namespace error message.
    I tried to attach the below DLL, but it is not there.

    using System.Web.UI.WebControls.WebParts;
    using System.Net.Mail;

    Please guide me on this?

    Author: Mrs. Meetu Choudhary Nanda03 Oct 2008 Member Level: Gold   Points : 1

    Mr. Narayanan Sukumaran
    I have attached the files here please check them and try.. then let me know

    --
    Thanks and Regards
    Meetu Choudhary

    Author: sheetal jagdale04 Oct 2008 Member Level: Silver   Points : 2

    Yes ,This is working.
    Thanx , How to attached some file with this ??
    & if i want to send same mail to some say 5000 people ,where the email addresses comes from database (sql server2005),how i will do this ?? how much time it takes to send mail to 5000 people ??

    Pl.answer

    Thanx anyway
    sheetal

    Author: sheetal jagdale04 Oct 2008 Member Level: Silver   Points : 2

    Yes ,This is working.
    Thanx , How to attached some file with this ??
    & if i want to send same mail to some say 5000 people ,where the email addresses comes from database (sql server2005),how i will do this ?? how much time it takes to send mail to 5000 people ??

    Pl.answer

    Thanx anyway
    sheetal

    Author: Mrs. Meetu Choudhary Nanda04 Oct 2008 Member Level: Gold   Points : 2

    Hi, sheetal ji

    If you want to send it to the more then one people then you can use cc and bcc list it is already implemented in the function u just have to fetch the list from the database and then you can pass that comma separated string to the cc or bcc parameter...




    --
    Thanks and regards
    Meetu Choudhary

    Author: Babu20 Oct 2008 Member Level: Bronze   Points : 1

    Hi All,
    Can you send the code for sending mail in ASP.NET using VB. Please it’s very urgent. Now I’m Begging level for developing the website. So please send the code as soon as possible

    Author: Mrs. Meetu Choudhary Nanda21 Oct 2008 Member Level: Gold   Points : 2

    Mr. Babu

    Please Try This and Let Me know if any problems


    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    Imports System.Net.Mail

    Public Partial Class [Default]
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Calling the function SendMail
    Response.Write(SendMail("meetuchoudhary@gmail.com", "meetudmeet@gmail.com", "meetudmeet@yahoo.com", "Test Mail", "Test Mail Body"))
    End Sub

    Public Function SendMail(ByVal toList As String, ByVal from As String, ByVal ccList As String, ByVal subject As String, ByVal body As String) As String
    Dim message As New MailMessage()
    Dim smtpClient As New SmtpClient()
    Dim msg As String = String.Empty
    Try
    Dim fromAddress As New MailAddress(from)
    message.From = fromAddress
    message.[To].Add(toList)
    If ccList <> Nothing AndAlso ccList <> String.Empty Then
    message.CC.Add(ccList)
    End If
    message.Subject = subject
    message.IsBodyHtml = True
    message.Body = body
    smtpClient.Host = "mail.server.com"
    smtpClient.Port = 25
    smtpClient.UseDefaultCredentials = True
    smtpClient.Credentials = New System.Net.NetworkCredential("info@server.com", "password")

    smtpClient.Send(message)
    msg = "Successful"
    Catch ex As Exception
    msg = ex.Message
    End Try
    Return msg
    End Function

    End Class

    ==
    Thanks and Regards
    Meetu Choudhary

    Author: Gaurav Aroraa31 Oct 2008 Member Level: Gold   Points : 2

    Hi Meetu!

    All above is great I must appreciate you for that.
    One more thing, If I am not wrong then we also can send the mail using Stored Proc.
    If yes, then why should we go for that much heavy coding.
    With the use of SQL we can mange the same very well.

    Hope you are agree with me.

    Thansk & regards,
    Gaurav Arora

    Author: Mrs. Meetu Choudhary Nanda31 Oct 2008 Member Level: Gold   Points : 1

    Hi Gaurrav,

    Yes i do agree with you but what if in some sites we do not use datbases and still we want to send feebacks or other stuff for this only need i don't think that we must go for database and stored procedures.

    Hope you too agree with me

    ++
    Thanks nd Regards
    Meetu Choudhary

    Author: Nandini P05 Nov 2008 Member Level: Gold   Points : 1

    hi!!

    Thank you so much for this code snippet..i used this snippet after trying other codes which of course doesn't work..and your code worked for me..it is easy to understand and use even after some modifications..
    Thanks again..
    keep doing the great work :)

    Author: usha11 Feb 2009 Member Level: Silver   Points : 1

    hi!

    i got the error that is
    "failure sending mail"
    one more question 1) how to check that my system has e_mail exchange server
    plz guide me ....
    thanks and regards
    usha

    Author: Mrs. Meetu Choudhary Nanda11 Feb 2009 Member Level: Gold   Points : 1

    Hi Usha,
    I will suggest you once download the files with this article and run them still u get the error then display the error message in the label and let me know the error then i may help you

    Author: usha11 Feb 2009 Member Level: Silver   Points : 1

    hi!

    i download ur code from this article.........

    it is working fine now. thanks a lot....

    one small question.. i want to type the To address in a TextBox and send the mail to that particular person.. how to use it

    thanks and regards
    usha

    Author: Mrs. Meetu Choudhary Nanda11 Feb 2009 Member Level: Gold   Points : 1

    simply pass the value of the text property of the textbox in the parameters of sendmail function

    happy codding if any other query feel free to ask

    Author: usha11 Feb 2009 Member Level: Silver   Points : 1

    hi

    thanks a lot Mr. Meetu Choudhary..

    all works fine


    thanks
    usha

    Author: Mrs. Meetu Choudhary Nanda11 Feb 2009 Member Level: Gold   Points : 1

    Dear Usha Ji
    You are most welcome

    but i would like to tell you one thing

    that

    I am Miss Meetu Choudhary

    not

    Mr. Meetu Choudhary

    any ways happy to help you

    :)

    Author: baiju23 Mar 2009 Member Level: Silver   Points : 2

    hi meetu your code is not working
    smtpClient.Host = "mail.server.com";
    smtpClient.Port = 25;
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");

    what is mail.server.com , is it common for every machine,portno =25 is it also common. and "info@server.com", "password".
    pls help me baiju

    Author: Mrs. Meetu Choudhary Nanda23 Mar 2009 Member Level: Gold   Points : 1

    hi baiju
    i have attached the working version of the code with the article

    and ya
    the host will be anything like
    smtp.gmail.com
    or any orther host through which u will send ur mails

    Author: yoshini23 Mar 2009 Member Level: Bronze   Points : 2

    im yoshini,

    My whole project is to detect documents in pigeonholes and notify the user when documents available using email.Only for 3 users. Im now doing the interfacing part. Im using the 8051 microcontroller connected using rs 232 to the pc..Im confuse about which type of interface and GUI i will be able to use and how to store the database of the users? are there any other methods and references for me to refer? please help me.. Any recommended website? I need to explore myself more... thanks!!!

    Author: Nisar18 Apr 2009 Member Level: Gold   Points : 1

    hey meetu, i am search this code from many days, i am very to find it, but please guide me one thing,
    mail.tatiwalaje.com
    this mail service is free for ever? mean to say can i relay on this, can i use this mail service for my contact us page?

    Author: Mrs. Meetu Choudhary Nanda19 Apr 2009 Member Level: Gold   Points : 2

    NO this (mail.tatiwalaje.com) name space is not free for ever actually this is my client's space i just put it for example and you can use your gmail account instead of this the port will be 587 and the server will be pop.gmail.com or smtp.gmail.com and one more line you have to add is the requiredssl connection and it should be true. for gmail


    ++
    Regards
    Meetu Choudhary

    Author: Nisar19 Apr 2009 Member Level: Gold   Points : 2

    thanks meetu for quick reply, i am not very expert, so please can you change your code according to gmail, yahoo or hotmail, but i actually want to not give my own email and password, as in your application, we can send mail through any email, no need to give password, can i do this with gmail? or is there any free mail serviced that work like mail.tatiwalaje.com

    Author: Mrs. Meetu Choudhary Nanda19 Apr 2009 Member Level: Gold   Points : 1

    i am affraid that any mail server will give you this kind of service but you can use the service of the domain you will register they will give you this service.

    Author: Nisar19 Apr 2009 Member Level: Gold   Points : 2

    yes my company has their own domain, and my task is to make a module where user can email each other internally, i write a code for gmail but they tell me that every user is not related to gmail and everyone not want to give their own password, then i use your code and its work exactly what they want, thats why i ask from you about mail.tatiwalaje.com, ok i actually want from you to please guide me what i ask from my company,
    smtp server?
    UserName?
    Password?
    Its enough?

    Author: Nisar19 Apr 2009 Member Level: Gold   Points : 1

    thanks meetu, i am using your code but i change the smtp server, and again its work fine, i am using my company's domain with my official email and password to test, and its work fine, sorry if i ask the question that have no meaning

    Author: Mrs. Meetu Choudhary Nanda19 Apr 2009 Member Level: Gold   Points : 2

    No Problem i am happy to help You

    Author: bajibabusk20 Apr 2009 Member Level: Gold   Points : 2

    Yes ,This is working.
    Thanx , How to attached some file with this ??
    & if i want to send same mail to some say 5000 people ,where the email addresses comes from database (sql server2005),how i will do this ?? how much time it takes to send mail to 5000 people ??

    Pl.answer

    Thanx anyway
    bajibabu

    Author: Mrs. Meetu Choudhary Nanda21 Apr 2009 Member Level: Gold   Points : 1

    yes you can fetch the address from the database as yu get the value for any other variable.. just pass the valur to the to paramerter of the function and time taken will depend on the server load...

    Author: charmii29 May 2009 Member Level: Bronze   Points : 1

    hey hi to all ,,

    well i m making 1 news letter form..
    this code is very fine for manual sending .. bt wht if i want to send it in bulk users at particular time ( like every day on 5 PM ) with 1 html file attachment ? .. plz help me out ..


    thanks :)

    Author: charmii29 May 2009 Member Level: Bronze   Points : 1

    hey hi to all ,,

    well i m making 1 news letter form..
    this code is very fine for manual sending .. bt wht if i want to send it in bulk users at particular time ( like every day on 5 PM ) with 1 html file attachment ? .. plz help me out ..


    thanks :)

    Author: arun02 Jun 2009 Member Level: Bronze   Points : 2

    hi i am new to mailing concept ..i used the settings given below..
    //CODE

    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 465; // i also tried for port 25
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Credentials = new System.Net.NetworkCredential("mygmail_id@gmail.com", "mygmail_password");

    //CODE

    I got this error message "The operation has timed out"

    can u suggest me what is the solution for this error??
    do i need to change any settings??

    Thanks in advance..

    Author: Mrs. Meetu Choudhary Nanda03 Jun 2009 Member Level: Gold   Points : 1

    Instead of

    smtpClient.Port = 465; // i also tried for port 25

    try

    smtpClient.Port = 587

    in dotnet 587 is the port we use for gmail

    Author: arun03 Jun 2009 Member Level: Bronze   Points : 1

    Thank you Meetu for ur quick reply, i got solution in port 587

    Author: Mrs. Meetu Choudhary Nanda03 Jun 2009 Member Level: Gold   Points : 1

    You are most welcome arun.

    Thanks..

    Author: shakthydoss29 Aug 2009 Member Level: Bronze   Points : 2

    Hi miss meetu i tried ur code with little modification
    but i get error ..

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.
    WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net.Mail;

    namespace sentmail
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    //Calling the function SendMail
    Response.Write(SendMail("shakthydoss@gmail.com", "sakthida@gmail.com", "shakthydoss@gmail.com", "Test Mail", "Test Mail Body"));
    }

    public string SendMail(string toList, string from, string ccList, string subject, string body)
    {
    MailMessage message = new MailMessage();
    SmtpClient smtpClient = new SmtpClient();
    string msg = string.Empty;
    try
    {
    MailAddress fromAddress = new MailAddress(from);
    message.From = fromAddress;
    message.To.Add(toList);
    if (ccList != null && ccList != string.Empty)
    message.CC.Add(ccList);
    message.Subject = subject;
    message.IsBodyHtml = true;
    message.Body = body;
    smtpClient.Host = "mail.server.com";
    smtpClient.Port = 487;
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Credentials = new System.Net.NetworkCredential("myid@gamil.com", "password");

    smtpClient.Send(message);
    msg = "Successful";
    }
    catch (Exception ex)
    {
    msg = ex.Message;
    }
    return msg;
    }

    }
    }

    Error :- Failure sending mail.
    looking forward for ur kind reply....

    Author: pankaj singh09 Jan 2010 Member Level: Bronze   Points : 2

    hello neetu

    i have tried ur code but it give message;


    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'smtpClient' does not exist in the current context

    Source Error:



    Line 42: message.IsBodyHtml = true;
    Line 43: message.Body = body;
    Line 44: smtpClient.Host = "mail.gmail.com";
    Line 45: smtpClient.Port = 587;
    Line 46: smtpClient.UseDefaultCredentials = true;


    Source File: c:\Documents and Settings\pankaj\Desktop\mysite\enquiry.aspx.cs Line: 44




    the actual code is:-
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Net.Mail;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    string f = TextBox1.Text;
    string s = TextBox2.Text;
    string b = TextBox3.Text;

    Response.Write(SendMail(f,s,b) );

    }
    public string SendMail( string from, string subject, string body)
    {
    MailMessage message = new MailMessage();
    SmtpClient sc = new SmtpClient();
    string msg = string.Empty;
    try
    {
    MailAddress fromAddress = new MailAddress(from);
    message.From = fromAddress;
    message.To.Add("exesolutionsinfo@gmail.com");

    message.Subject = subject;
    message.IsBodyHtml = true;
    message.Body = body;
    smtpClient.Host = "mail.gmail.com";
    smtpClient.Port = 587;
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password");
    smtpClient.Send(message);
    msg = "Successful";
    }
    catch (Exception ex)
    {
    msg = ex.Message;
    }
    return msg;
    }
    }
    plzzzzzzzzzz help me out?
    pankaj Singh

    Author: Manindra Kumar Upadhyay02 Apr 2010 Member Level: Gold   Points : 1

    try this link:
    http://manindra.net/post/2010/03/29/Send-email-from-Aspnet.aspx

    Author: Shivraj Singh Rajawat26 Jul 2010 Member Level: Silver   Points : 1

    hello mam,

    This is indeed nice code for sending email. Can u tell me about specifying username & password. Is it sender email id's username, password or hosting panel's username & password.

    thanks & regards


    Shiv

    Author: Er. Ram Singh06 Sep 2010 Member Level: Gold   Points : 2

    using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net.Mail;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) {//Calling the function SendMail Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body")); } public string SendMail(string toList, string from, string ccList, string subject, string body) { MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); string msg = string.Empty; try { MailAddress fromAddress = new MailAddress(from); message.From = fromAddress; message.To.Add(toList); if (ccList != null && ccList != string.Empty) message.CC.Add(ccList); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; smtpClient.Host = "mail.server.com"; smtpClient.Port = 25; smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password"); smtpClient.Send(message); msg = "Successful"; } catch (Exception ex) { msg = ex.Message; } return msg; }}

    Author: Venkatesan Prabu .J08 Sep 2010 Member Level: Gold   Points : 1


    Thats a very big communication.. :-)

    Cheers,
    Venkatesan Prabu .J
    http://venkattechnicalblog.blogspot.com/

    Author: raja paturu10 Sep 2010 Member Level: Gold   Points : 2

    Hello meetu madam,

    i have one content and nearly 4000 mail id's, and want to send the content to all the 4000 mail id's , instead of sending one by one mail.

    At this point of time, can i use the above mentioned code?

    in the above code,
    can i modify in this block?
    protected void Button1_Click(object sender, EventArgs e)
    {
    //Calling the function SendMail
    Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body"));
    }

    ------


    protected void Button1_Click(object sender, EventArgs e)
    {
    //Calling the function SendMail
    Response.Write( SendMail("mail1","mail2","mail3"..."mail4000","Test Mail","Test Mail Body"));
    }

    i need to add all the 4000 mail ids in button1_click block ?


    thanks 'n' regards
    raja

    Author: vidhya19 Nov 2010 Member Level: Bronze   Points : 1

    hi,

    im getting follwing error
    The remote name could not be resolved: 'smpt.gmail.com'

    pls tel me solution for this.

    With Regards,
    Vidhya.C

    Author: Charles24 Mar 2011 Member Level: Bronze   Points : 1

    Hello Meetu Madam,
    I have tried your code on yahoo.com but I get error message - message sending failed. May I please request you help me the mail over yahoo.
    In fact I have a datagrid containing names and email addresses of people. I want to know:
    (1) How can I retrieve name and address of members selected from the datagrid (datagrid has a checkbox column to select chosen members)
    (2) How can I retrieve different email domains form each address and send them all a generic mail message?
    Madam, I am quite novice and I will heartily appreciate your help.

    Regards
    Charles

    Guest Author: Raman23 May 2012

    its not working its showing failure sending msg,

    please help me out this thanx

    Raman

    Author: Raju Puppala22 Sep 2012 Member Level: Bronze   Points : 0

    Hai...freinds.Iam developing one college project
    I want send mails to all my students in my college which type of code i need to write using c#


    Thanks@Regards
    Rajupuppala

    Guest Author: Rahul27 Oct 2012

    Hey
    i hace copied the above cod dito
    no error is there
    but i m getting msg sending falied
    plz help me what to do
    i want to DO it yaar

    Author: Mrs. Meetu Choudhary Nanda30 Oct 2012 Member Level: Gold   Points : 0

    Rahul that is because you need to change the server credentials. you need to use the working server creds the one showed in the example are just demo

    Guest Author: Rahul31 Oct 2012

    Hey Meetu Mam

    It would be better if u could tell me more specifically about it.I am having doubt about working sever,what is this working server Nd what credentials i need to change.
    and i also please tell the meaning of these lines.
    What i need to mention here.
    1.
    smtpClient.Host = "mail.server.com";
    2.
    smtpClient.Credentials = new System.Net.NetworkCredential("mr.khurana@gmail.com", "my-password");

    Thank you in advance......

    Guest Author: sreehari23 Nov 2012

    Hi meetu

    im getting the same error what mr.rahul has got and im using the working server credentials.please help me

    Author: Mrs. Meetu Choudhary Nanda27 Nov 2012 Member Level: Gold   Points : 4

    Sreehari,

    I am not sure what credentials you are using but if you have write the exact credentials and the correct port no then it should work. It worked for me and for many others too. or if you can provide the error details then also i might help you or you can post the question in forms in case i wont get time to check in here then someone will help you you can mention the reference of this article you can try downloading the attached files they work fine

    Guest Author: padmapriya11 Feb 2013

    hi meetu,
    i am using your code. but not send mail automatically only i get the message "successful". i am ask to you one question what i give smtpclient host and port no i don't know which i give.please help me.
    Thank you

    Author: Mrs. Meetu Choudhary Nanda13 Feb 2013 Member Level: Gold   Points : 2

    padmapriya
    Try downloading the attached files and execute them may be that help and you can use your gmail credentials or any other for the smtpclient host and port no according to what you are using

    Guest Author: srikanth reddy24 Mar 2013

    hello miss Meetu...

    i am trying to build a mail in which we use gridview from database with checkbox and some details outside the gridview. i need a code for sending all these details in a mail when we click submit button

    Guest Author: srikanth reddy24 Mar 2013

    hello miss Meetu...

    i am trying to build a mail in which we use gridview from database with checkbox and some details outside the gridview. i need a code for sending all these details in a mail when we click submit button

    Author: srikanth reddy p24 Mar 2013 Member Level: Bronze   Points : 2

    hello meetu....
    i am trying to build a mail for gridview and other text boxes in a page. i want a code to send the details present in a gridview with checkbox selected and also other details outside text boxes when we click submit button

    Author: srikanth reddy p25 Mar 2013 Member Level: Bronze   Points : 0

    can u get me the details asap please and i am also trying for binding dropdownlists with search button for gridview

    Author: Mrs. Meetu Choudhary Nanda05 Apr 2013 Member Level: Gold   Points : 0

    srikanth reddy,
    I don't know about which details you are talking about be specific and if you have problems i think forums section is best to get your query solved.

    Regards.

    Guest Author: gopinath22 Apr 2013

    Dear Miss Meetu Choudhary,
    I need help, I am using same code for sending mail, but my mails are received in spam folder (gmail and hotmail), in yahoo mail its working fine.
    if i send mail from web server, its working fine, mail is going to inbox.
    I cant find the problem where its happening, can you help me please

    Author: Ultimaterengan09 Feb 2014 Member Level: Gold   Points : 5

    Try like this also

    First we need to import System.Web.Mail namespace. The system.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS message component.

    To Add this reference follow below steps

    1)On the project menu click add reference

    2)After That click .net Tab, locate System.Web.ddl, and then click Select.
    3)Click ok in the add references.


    Design Page

















    Coding Page



    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net.Mail;
    using System.Net;

    public partial class _Default : System.Web.UI.Page
    {
    protected void btnSend_Click(object sender, EventArgs e)
    {
    try
    {
    MailMessage msg = new MailMessage(txtFromMailID.Text.ToString().Trim(), txtTomailid.Text.ToString().Trim(), txtsubject.Text.ToString(), txtbody.Text.ToString());
    MailAddress SendCC = new MailAddress(txtCC.Text.ToString());
    msg.CC.Add(SendCC);
    SmtpClient mailClient = new SmtpClient(txtsmtpaddress.Text.ToString().Trim(), Convert.ToInt32(txtPortAddress.Text.ToString().Trim()));
    NetworkCredential NetCrd = new NetworkCredential(txtFromMailID.Text.ToString(), txtPassword.Text.ToString());
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = NetCrd;
    if (Convert.ToInt32(txtPortAddress.Text.ToString().Trim()) == 587)
    {
    mailClient.EnableSsl = true;
    }
    else
    {
    mailClient.EnableSsl = false;
    }
    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

    mailClient.Send(msg);
    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertScript", "Mail Sent", true);
    }
    catch (Exception ex)
    { Page.ClientScript.RegisterStartupScript(this.GetType(), "alertScript", ex.Message, true);
    }
    }
    }



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: