locked
sending mails through asp.net to all web wide mail id's RRS feed

  • Question

  • hi all,

    below code is working fine for localhost..but i want to send through webwide..like to gmail..hotmail..yahoo..how its possible..wt code chagnges makes this possib

    protected void Button1_Click(object sender, EventArgs e)
      {
        MailMessage obj = new MailMessage();
        // MailAttachment obj1 = new MailAttachment(FileUpload1.PostedFile.FileName);
        obj.To = TextBox1.Text;
        obj.From = TextBox2.Text;
        obj.Subject = TextBox3.Text;
        obj.Body = TextBox4.Text;
        SmtpMail.SmtpServer = "localhost";
          SmtpMail.Send(obj);
        Label1.Text="Mail Sent Succesfully";
    
      }
     <system.net>
      <mailSettings>
       <smtp from="mail.kesineni.net">
        <network host="smtp.mail.kesineni.net" port="587" userName="srilakshmi" password="holidays"/>
       </smtp>
      </mailSettings>
     </system.net>

    le?

    Monday, August 2, 2010 10:39 AM

Answers

  • H sril,

    I think you aren't in the good forum ;)

    But i have an idea for you : you could use a coded SmtpClient as in MSDN exemple :

    http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    • Proposed as answer by JeremyJeansonMVP Monday, August 2, 2010 3:16 PM
    • Marked as answer by Andrew_Zhu Monday, August 9, 2010 7:45 AM
    Monday, August 2, 2010 10:48 AM
  • Agree with Jeremy, the MSDN help has pretty straightforward samples of how to use the System.Net.Mail namespace. :)

    Just a quick note on a few things I spotted:

    1. The obj.To doesn't take a string. It's a collection of MailAddress objects. For example: 

          obj.To.Add(new MailAddress("toAddress@whatever.com"));

    2. The obj.From doesn't take a string either. It's an instance of MailAddress. For example:

          obj.From = new MailAddress("fromAddress@whatever.com");

    3. Not sure what the "SmtpMail" object is, but you need an instance of SmptClient, and use it to Send() the obj.

    Hope this helps.


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Proposed as answer by JeremyJeansonMVP Monday, August 2, 2010 3:16 PM
    • Marked as answer by Andrew_Zhu Monday, August 9, 2010 7:45 AM
    Monday, August 2, 2010 2:23 PM

All replies

  • H sril,

    I think you aren't in the good forum ;)

    But i have an idea for you : you could use a coded SmtpClient as in MSDN exemple :

    http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    • Proposed as answer by JeremyJeansonMVP Monday, August 2, 2010 3:16 PM
    • Marked as answer by Andrew_Zhu Monday, August 9, 2010 7:45 AM
    Monday, August 2, 2010 10:48 AM
  • Agree with Jeremy, the MSDN help has pretty straightforward samples of how to use the System.Net.Mail namespace. :)

    Just a quick note on a few things I spotted:

    1. The obj.To doesn't take a string. It's a collection of MailAddress objects. For example: 

          obj.To.Add(new MailAddress("toAddress@whatever.com"));

    2. The obj.From doesn't take a string either. It's an instance of MailAddress. For example:

          obj.From = new MailAddress("fromAddress@whatever.com");

    3. Not sure what the "SmtpMail" object is, but you need an instance of SmptClient, and use it to Send() the obj.

    Hope this helps.


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    • Proposed as answer by JeremyJeansonMVP Monday, August 2, 2010 3:16 PM
    • Marked as answer by Andrew_Zhu Monday, August 9, 2010 7:45 AM
    Monday, August 2, 2010 2:23 PM
  •  

     

    when am trying to execute below code...am getting error

    "The specified string is not in the form required for an e-mail address"

    MailMessage obj = new MailMessage(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text);
    
    // MailAttachment obj1 = new MailAttachment(FileUpload1.PostedFile.FileName);
    
    obj.To.Add(new MailAddress (TextBox1.Text));
    
    MailAddress from=new MailAddress("mail.kesineni.net");
    
    
    
    obj.Subject = TextBox3.Text;
    
    obj.Body = TextBox4.Text;
    
    
    SmtpClient client = new SmtpClient();
    
    client.Host = "smtp.mail.kesineni.net";
    
    client.Credentials = new System.Net.NetworkCredential(@"mail.kesineni.net", "holidays");
    
    client.EnableSsl = true;
    
    client.Send(obj);
    
    obj.Dispose();
    
    
    Label1.Text="Mail Sent Succesfully";
    
    
    Tuesday, August 3, 2010 7:24 AM
  • Hi Sril,

    Your error is here -> MailAddress from=new MailAddress("mail.kesineni.net");

    mail.kesineni.net isn't an mail address. Put an mail here, not a domaine name.

    MailAddress from=new MailAddress(myname@mail.kesineni.net);

    ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Tuesday, August 3, 2010 7:52 AM
  • still it was throwing error..

    "smtp exception was unhandled by usercode:Failure sending mail."

    Friday, August 6, 2010 5:05 AM
  • Hi sril,

    Your smtp (mail.kesineni.net) provider need an authentication?

    are you sure this is the SMTP?


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Friday, August 6, 2010 7:08 AM
  • i dnt know how to make authentication.plz..can u tell me the process..?
    Friday, August 6, 2010 7:20 AM
  • hi sril,

    you done it in your code :

    SmtpClient client = new SmtpClient();
    
    client.Host = "smtp.mail.kesineni.net";
    
    client.Credentials = new System.Net.NetworkCredential(@"mail.kesineni.net", "holidays");
    
    client.EnableSsl = true;
    
    

    Are you sure :

    do you need this crendentials ? (and is it a corrrect account?)

    do you need SSL?

    Ty without and you'll know if it work

     


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Friday, August 6, 2010 7:23 AM
  • hi jeanson,

     i tried as u suggested. i mean i removed that credentials and tried.still it was through same error as i stated above."failure sending mail"

    Friday, August 6, 2010 7:47 AM
  • it worked one time before and it didn't work yet?!!!

    are you sure you didn't change something else?

    Try those cases :

    1 : none credentials , none ssl

    2 : credentials , none ssl

    3 : none credentials , ssl


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Friday, August 6, 2010 7:50 AM
  • Sril,

    If you are still getting the same error after trying those cases listed by Jeremy, you may want to expand the exception, and there should be an Inner Exception which gives you a more specific message about the error you are encountering. Let us know what that InnerException is.

    Thanks!

     


    Cecilia Leung This posting is provided "AS IS" and confers no rights or warranties.
    Friday, August 6, 2010 7:57 AM