email problem

Discussion in 'Email' started by ganeshnilgris, Feb 28, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. web.config details
    -------------------
    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="localhost" password="password" port="587" userName="[email protected]" />
    </smtp>
    </mailSettings>
    </system.net>


    mail sending code
    --------------

    ---getting the username and mail id and sending it

    string userName = CreateUserWizard1.UserName;
    string emailAddress = CreateUserWizard1.Email;

    // Lets get the user's id
    Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey;

    // Now lets create an email message
    StringBuilder emailMessage = new StringBuilder();
    emailMessage.Append("Thank you for creating an account with OnlinePersonalDairy.com");
    emailMessage.Append("<br />");
    emailMessage.Append("Please click the below link to activate your account <br />");
    emailMessage.Append(string.Format("<a href='http://www.onlinepersonaldairy.com/ConfirmCode.aspx?userName{0}&Id={1}'>Activate {0} </a>", userName, userId.ToString()));
    MailMessage email = new MailMessage();
    email.From = new MailAddress("[email protected]");
    email.To.Add(new MailAddress(emailAddress));
    email.Subject = "Please activate your account with Onlinepersonaldairy.com";
    email.Body = emailMessage.ToString();
    email.IsBodyHtml = false;


    try
    {
    // Send the email
    SmtpClient client = new SmtpClient();
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Send(email);

    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }


    result
    ------
    no error

    but the reciepent is not getting the mail

    any help
     
  2. Hi,
    I didn't spot any errors there, same sort of code I'm using but I use port 25.
    I'd suggest trying it without the StringBuilder, use http://www.bing.com/ and you can find lots of examples in C#.
    All the best,
    Mark
     
  3. let me have the question like this

    i want to test the automatic mail working with the local host without uploading the code to the site. Next when i am user authentication i use the hosted server and not the local server. well now can i test the automatic server in this kind of scenerio
     
  4. Ramses

    Ramses Guest

    If you're using 'localhost' to send out email, you do not need to authenticate because you're not hitting your SMTP server.

    If you plan on using "smtp.onlinepersonaldairy.com", then you'll have to specify the username/password, and you can leave the default port (25) when sending.

    Let us know if you get any errors with either one though, and we can help you troubleshoot it.
     
  5. Sending Email from my site

    Hi guys,

    I really need help understanding something. I am developing my site and I want users to be able to contact me by sending me an email from my contactUs.aspx page. Below is the code I have written:

    Code:
    protected void sendButton_Click(object sender, EventArgs e)
        {
            //Creating an instance of the mail object
            MailMessage myEmail = new MailMessage();
    
            //Set Addresses
            myEmail.From = new MailAddress(FromEmailTextBox.Text, fullNameTextBox.Text);
            myEmail.To.Add(new MailAddress("[email protected]"));
    
            //Set the content
            myEmail.Subject = subjectTextBox.Text.Trim();
            myEmail.Body = msgTxtBox.Text.Trim();
            myEmail.IsBodyHtml = true;
            
            //try
            //{
                //Set the SMTP and send email.
                SmtpClient mySmtp = new SmtpClient();
                mySmtp.Send(myEmail);
    
                statusLabel.ForeColor = Color.Navy;
                statusLabel.Text = "Congratulations!! You have reached us successfully. We will get back to you soon!";
            //}
    
            //catch (SmtpException ex)
            //{
            //    statusLabel.ForeColor = Color.Red;
            //    statusLabel.Text = "Sorry, there was a problem. " + ex.Message;
            //}
                
        }
    
    In my web.config file; I have these code:

    1. first I tried this:

    Code:
    <system.net>
        <mailSettings>
          <smtp>
            <network host="localhost" port="25" />
          </smtp>
        </mailSettings>
      </system.net>
    

    2. Second, I tried using my smtp server.

    Code:
    <system.net>
        <mailSettings>
          <smtp>
            <network host="smtp.myDomain.org" port="25" username="[email protected]" password="password" />
          </smtp>
        </mailSettings>
      </system.net>
    

    I get the same error above. Am I doing the right thing? I have not uploaded to my server yet. I am testing locally.

    Thanks guys.


    With the above code, it gives me this error:

    2.
     
  6. Hi,
    Your localhost version is correct and it will not work on your end unless you run an SMTP server.
    This is one of the things you have to test on the DASP server live.
    There are some workarounds but the best way is to test on the live server.
    All the best,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page