Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I am able to send the mail if i execute the solution in local host but after publishing my solution everything seems to be working fine but am not able to send mail from my site what may be the reason??
Posted
Comments
[no name] 19-Jul-13 6:56am    
Out of the thousand ways to screw things up, you expect us to guess which one way you picked?
Arpit Shrivastava 19-Jul-13 7:31am    
Is your SMTP Server is ready to queued your mails. Please check first...
naveend915 20-Jul-13 3:36am    
My code is like this its working fine when i run the solution in local system but am not not able to send mails when i published it to server what might be wrong??


public static bool SendMail(string MailTo, string MailCC, string MailBCC, string MailSubject, string MailBody)
{
bool _Success = false;
try
{

SmtpClient smtp = new SmtpClient();
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress("emailid@gmail.com");
message.To.Add(MailTo);
message.CC.Add(new MailAddress(MailCC));
message.Subject = MailSubject;
message.Body = MailBody;
smtp.EnableSsl = true;

smtp.Send(message);
_Success = true;

}
catch (Exception ex)
{
ExceptionLogging("Common", "Common.SendMail()", ex.ToString());
_Success=false;
}
return _Success;
}


web config file is like this

<system.net>
<mailsettings>
<smtp>
<network host="smtp.gmail.com" port="587" username="emailid@gmail.com" password="pwdxyz">



May be it is your network connection..try with this code and do it again.i did this my self and it worked properly..

C#
   public void mail(string receiver,string msg,string subject,string attachment1,string attachment2)
        {
            try
            {

                System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("cecblaboratory@gmail.com", receiver, subject, msg + " < CECB Experiments Results Updates >");

                MyMailMessage.IsBodyHtml = false;

                System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("xxxxx@gmail.com", "password");

                System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

                string file = attachment1;
                string file2 = attachment2;
                Attachment attach = new Attachment(file);
                Attachment attach2 = new Attachment(file2);

                // Add the file attachment to this e-mail message.

                MyMailMessage.Attachments.Add(attach);
                MyMailMessage.Attachments.Add(attach2);

                mailClient.EnableSsl = true;
                mailClient.UseDefaultCredentials = false;
                mailClient.Credentials = mailAuthentication;
                mailClient.Send(MyMailMessage);
                MessageBox.Show("Mail sent success!");

               

            }


            catch (Exception )
            {
                MessageBox.Show("Check your Network Connection", "Invalid or Empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
              

            }


////on button click event call the above method with your real data

  mail(txtreceiver.Text,txtmessage.Text,txtMailSubject.Text,lblAttach2.Text,lblAttach1.Text);


hope this will work..
 
Share this answer
 
v2
Comments
naveend915 22-Jul-13 12:33pm    
thanku...:)
Muthu Karunarathna 22-Jul-13 13:13pm    
:)
Probably, you need to provide authentication when you try to send form your website - your local development machine is probably using a different email service, and may be configured to accept anonymous login, or use your windows login.

If you don't know how to provide authentication, see this tip: Sending an Email in C# with or without attachments: generic routine.[^]
 
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