Tech Off Thread

9 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Sending mail with ASP.net 2.0 c#

Back to Forum: Tech Off
  • User profile image
    Metal MilitiA

    i am trying to write a code that can send mails trough the web what is wrong with this

    protected
    void sendbtn_Click(object sender, EventArgs e)

    {

    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(txtEmail.Text,"reservation@palmerahotel.com");

    string txtemailto = (txtEmail.Text);

    try

    {

    message.Body = (txtemailto);

    System.Net.Mail.SmtpClient sender = new System.Net.Mail.SmtpClient();

    sender.Credentials.GetCredential();



    - error CS0136: A local variable named 'sender' cannot be declared in this scope because it would give a different meaning to 'sender', which is already used in a 'parent or current' scope to denote something else
    - error CS0117: 'object' does not contain a definition for 'Credentials'

    this should give you a idea

    also there is one more thing what should i write down to the authentication type?!

    thanks... Sevki

  • User profile image
    Sven Groot

    Your function has a parameter named sender, so you cannot also have a local variable named sender. Name the SmtpMail variable something else instead.

  • User profile image
    Metal MilitiA

    thanks it works
    what should the auth type be

  • User profile image
    Ion Todirel

    why they don't make sender's type like control type?, for ex:

    button1.Click += delegate(Button sender, EventArgs e) {};

  • User profile image
    blowdart

    Ion Todirel wrote:
    why they don't make sender's type like control type?, for ex:

    button1.Click += delegate(Button sender, EventArgs e) {};


    Because then you couldn't use the same event for more than one control type.

    Smiley

  • User profile image
    Metal MilitiA

    here is the new deal

    protected void sendbtn_Click(object sender, EventArgs e)

    {

    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(txtEmail.Text,"reservation@palmerahotel.com");

    string txtemailto = (txtEmail.Text);

    string smtphostu = ("mail.palmerahotel.com");

    try

    {

    message.Body = (txtemailto);

    System.Net.Mail.SmtpClient send3r = new System.Net.Mail.SmtpClient();

    send3r.Credentials.GetCredential(???????);

    what should be written instead of ? please give example

  • User profile image
    Larsenal

    Metal MilitiA wrote:
    
    send3r.Credentials.GetCredential(???????);

    what should be written instead of ? please give example

    It depends on the authentication requirements on the SMTP server.  Are you trying to set the credentials?

  • User profile image
    Metal MilitiA

    yes but what are the authentication types for smtp

  • User profile image
    Larsenal

    Metal MilitiA wrote:
    

    yes but what are the authentication types for smtp



    Try using System.Net.NetworkCredential.  You can see an example here.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.