Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have problem with sending email with asp.net please help me.........
Posted
Comments
Uday P.Singh 3-Aug-11 7:05am    
can you tell us what error are you getting? or post your code..

protected void btnSendmail_Click(object sender, EventArgs e)
    {
      SmtpClient smtpClient = new SmtpClient();
      MailMessage message = new MailMessage();
      try
      {
          MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

          smtpClient.Host = "smtp.gmail.com";

          message.From = fromAddress;

          message.To.Add("admin1@yoursite.com");
          message.Subject = "Feedback";

          message.Body = txtMessage.Text;

          // Send SMTP mail
          smtpClient.Send(message);
          lblStatus.Text = "Email successfully sent.";
      }
      catch (Exception ex)
      {
          lblStatus.Text = "Send Email Failed." + ex.Message;
      }
    }
 
Share this answer
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net.Mime;

namespace Gmail
{
    public partial class Form1 : Form
    {
        //String path;
        MailMessage mail = new MailMessage();
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new System.Net.NetworkCredential("your e-mail id", "password");
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.EnableSsl = true;
            mail = new MailMessage();
            String[] addr = TextBox1.Text.Split(',');
            try 
            {
                mail.From = new MailAddress("your email id", "Developers", System.Text.Encoding.UTF8);
                Byte i;
                for( i = 0;i< addr.Length; i++)
                    mail.To.Add(addr[i]);
                mail.Subject = TextBox3.Text;
                mail.Body = TextBox4.Text;
                if(ListBox1.Items.Count != 0)
                {
                    for(i = 0;i<listbox1.items.count;i++)>
                    mail.Attachments.Add(new Attachment(ListBox1.Items[i].ToString()));
                }
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.ReplyTo = new MailAddress(TextBox1.Text);
                SmtpServer.Send(mail);
                MessageBox.Show("Mail Send");
            }
            catch (Exception ex){
            MessageBox.Show(ex.ToString());
            }
        }
}
}
 
Share this answer
 
v2
You can try this method:
C#
public Boolean SendingMail(string From, string To, string Subject,string Body)
	{
        try
        {
            MailMessage m = new MailMessage("mailidofSender", To);
            m.Subject = Subject;
            m.Body = Body;
            m.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "mail.google.com";
            NetworkCredential authinfo = new NetworkCredential("mailidfrom", "YourPassword");
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = authinfo;
            smtp.Send(m);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
	}
 
Share this answer
 
v2
string subject = "mention subject here";
        try
        {
            
            string emailTo = "uremail";
            string emailfrom="uremail";
            string body = "urbody";
            MailMessage objmail = new MailMessage(emailfrom, emailTo, subject,body);


            SmtpClient smtpclnt = new SmtpClient("smtp.gmail.com", 587);
            smtpclnt.DeliveryMethod = SmtpDeliveryMethod.Network;

            smtpclnt.UseDefaultCredentials = true;
            smtpclnt.EnableSsl = true;
            smtpclnt.Credentials = new System.Net.NetworkCredential("username", "password");
            smtpclnt.Send(objmail);
        }
        catch (Exception ex)
        {
           
        }
 
Share this answer
 
v2
Comments
RaviRanjanKr 3-Aug-11 7:29am    
Always Wrap your code with "Pre" tag.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900