0

Guys I am stuck with a problem and want your genuine suggestion..
Actually the problem is that i am trying to send a mail using c#.net..
There is no issues while sending mail but when i try to include an attachment with it is not taking the path of the concerned directory.. But when i am attaching the file from the root directory here i have my codes it is working absolutely well..
Plz look at the code below and give some suggestion to rectify the problem..

protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();

                mail.To.Add(txtTo.Text);
                mail.From = new MailAddress("orangesoftech2012@gmail.com");

                mail.Subject = txtSubject.Text;
                mail.Body = txtBody.Text;
                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(FileUpload1.FileName);
                mail.Attachments.Add(attachment);

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address

                smtp.Credentials = new System.Net.NetworkCredential
                ("orangesoftech2012@gmail.com", "orangeorange");
                //Or your Smtp Email ID and Password
                smtp.EnableSsl = true;
                smtp.Send(mail);
                Response.Write("<script language='javascript'>alert('MAIL SENT');</script>");
                Response.Write("<script language='javascript'>alert('Thank You for using VishalMail');</script>");
            }
            catch (Exception ex)
            {
                labelError.Text = ex.Message;

            }
        }
2
Contributors
8
Replies
17
Views
5 Years
Discussion Span
Last Post by kamilacbe
0

Needless to say i am using demo gmail id over here so better try with your own id while debugging changing the webconfig as well...

0

Guys i solved this problem.. The code is:

protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                
                mail.To.Add(txtTo.Text);
                mail.From = new MailAddress("orangesoftech2012@gmail.com");

                mail.Subject = txtSubject.Text;
                mail.Body = txtBody.Text;
                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(FileUpload1.PostedFile.InputStream,FileUpload1.FileName);
                mail.Attachments.Add(attachment);

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address

                smtp.Credentials = new System.Net.NetworkCredential
                ("orangesoftech2012@gmail.com", "********");
                //Or your Smtp Email ID and Password
                smtp.EnableSsl = true;
                smtp.Send(mail);
                Response.Write("<script language='javascript'>alert('MAIL SENT');</script>");
                Response.Write("<script language='javascript'>alert('Thank You for using VishalMail');</script>");
            }
            catch (Exception ex)
            {
                labelError.Text = ex.Message;

            }
        }
0

hii..

Even i did the same but then it didnt work for me ... it was working good in my previous project :-( ...couldnt find where i have gone wrong now...

0

hi..this is my code ....did the same

try
        {
            MailMessage mail = new MailMessage();

            mail.To.Add(txtto.text);
            mail.From = new MailAddress("username");

            mail.Subject = "well";
            mail.Body = "hii";
            // mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address

            smtp.Credentials = new System.Net.NetworkCredential
            ("username", "password");
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
0

1> IF not then configure the settings for system.net... mention the network credentials over dere alongwith the port number....

2> Change the IMAP/POP settings in your userid...

3> If still getting error paste the error msg with error img...

0

hii..

I forgot to update my username in webconfig file ...thank you soo much for your prompt reply...got fixed it ..:-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.