sending an email from my webpage -- 101

Discussion in 'Email' started by jekain314, Mar 18, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I sent this simple email string. The response was that the user was "greylisted" ...


    I sent the same email to [email protected] and the response was that [email protected] was not in the system.


    ---jim








    string from = "[email protected]";


    string to = "[email protected]";


    string subject = "test email";


    string body = "This is a test from GVOPS.COM?";


    SmtpMail.SmtpServer = "webmail.gvops.com";


    SmtpMail.Send(from, to, subject, body);
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    In general, you do not need to set this.


    The ASP.NET configuration tool just write several lines to your web.config. Is your code working though?


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. finally got it to work!! My lessons learned:


    (1) I used the email manager at DASP and set the password. Login as [email protected] and go to the setting page to do this.


    (2) use the web configuration wizard and set uo your smtp emil settings -- results in a web.congig section like this


    <mailSettings>


    <smtp from="[email protected]">


    <network host="webmail.yourDomain.com" password="xxxxxxxx" userName="[email protected]" />


    </smtp>


    </mailSettings>


    (3) first i tested this using the "password recovery" control in VS2008 --- this worked and sent me a new password to my email address -- no codeing!


    (4) Next I sent an email from my C# codebehind.








    using System;


    using System.Collections;


    using System.Configuration;


    using System.Data;


    using System.Linq;


    using System.Web;


    using System.Web.Security;


    using System.Web.UI;


    using System.Web.UI.HtmlControls;


    using System.Web.UI.WebControls;


    using System.Web.UI.WebControls.WebParts;


    using System.Net;


    using System.Net.Mail; ----- NOTE this namespace --- it is shown to be system.web.mail in other places


    using System.Xml.Linq;


    public partial class _Default : System.Web.UI.Page


    {


    protected void Page_Load(object sender, EventArgs e)


    {


    Label1.Text = "welcome " + User.Identity.Name;


    Profile.UserName = User.Identity.Name;


    MailAddress to = new MailAddress("[email protected]");


    MailAddress from = new MailAddress("[email protected]");


    MailMessage message = new MailMessage(from, to);


    message.Subject = "Using the new SMTP client.";


    message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";


    // Use the application or machine configuration to get the


    // host, port, and credentials.


    SmtpClient client = new SmtpClient();


    Console.WriteLine("Sending an e-mail message to {0} at {1} by using the SMTP host {2}.",


    to.User, to.Host, client.Host);


    client.Send(message);





    }


    }
     
  4. This is what was written to my web.config after I used the wizard.


    <mailSettings>


    <smtp from="[email protected]">


    <network host="smtp.gvops.com" password="XXXXXXX" userName="[email protected]" />


    </smtp>


    </mailSettings>
    Not sure about the write input for host, username, and pw -- i tried several versions.

    I simply tried to get a loginpassword using the VS2008"password recovery" control. The system tried to mail me my password at [email protected] (my correct email) and the error is as shown below.




    Server Error in '/GVOps4' Application.


    Mailbox unavailable. The server response was: <[email protected]> No such user here Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: <[email protected]> No such user here

    Source Error:








    Code:
    An unhandled exception was generated during the execution of the current web request. 

    Code:
    Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:





    Code:
    [SmtpFailedRecipientException: Mailbox unavailable. The server response was: <[email protected]> No such user here]
       System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException&amp; exception) +858231
       System.Net.Mail.SmtpClient.Send(MailMessage message) +2004
       System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
       System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +653
       System.Web.UI.WebControls.PasswordRecovery.AttemptSendPassword() +66
       System.Web.UI.WebControls.PasswordRecovery.OnBubbleEvent(Object source, EventArgs e) +101
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
    
     
  5. i read the KB and forum topics but cant get past zero.

    I am using VS2008 (freebie) and used the wizards at ...
    ASP.NET congiguration tool -> application configuration -> Configure SMTP e-mail settings

    The requested info looks like the stuff provided below.
    First question is, do I even need to fool with this? All I want to do is to send messages from my site (e.g, allow user to have his password sent to his address).













    <LABEL for=ctl00_ctl00_ctl00_content_content_content_ServerNameTextBox>ServerName:</LABEL>
    <input id=ctl00_ctl00_ctl00_content_content_content_ServerNameTextBox value=webmail.gvops.com name=ctl00$ctl00$ctl00$content$content$content$ServerNameTextBox>


    <LABEL for=ctl00_ctl00_ctl00_content_content_content_ServerPortTextBox>ServerPort:</LABEL>
    <input id=ctl00_ctl00_ctl00_content_content_content_ServerPortTextBox value=25 name=ctl00$ctl00$ctl00$content$content$content$ServerPortTextBox>
    * Server port should be a positive integer

    <LABEL for=ctl00_ctl00_ctl00_content_content_content_FromTextBox>From:</LABEL>
    <input id=ctl00_ctl00_ctl00_content_content_content_FromTextBox [email protected] name=ctl00$ctl00$ctl00$content$content$content$FromTextBox>










    Authentication:


    <input id=ctl00_ctl00_ctl00_content_content_content_NoneRadioButton onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$ctl00$content$content$content$NoneRadioButton\',\'\')', 0)" type=radio value=NoneRadioButton name=ctl00$ctl00$ctl00$content$content$content$Authentication>
    <LABEL for=ctl00_ctl00_ctl00_content_content_content_NoneRadioButton>None</LABEL>



    <input id=ctl00_ctl00_ctl00_content_content_content_BasicRadioButton type=radio CHECKED value=BasicRadioButton name=ctl00$ctl00$ctl00$content$content$content$Authentication>
    <LABEL for=ctl00_ctl00_ctl00_content_content_content_BasicRadioButton>Basic</LABEL>
    Choose this option if your e-mail server requires you to explicitly pass a user name and password when sending an e-mail message.



    <LABEL id=ctl00_ctl00_ctl00_content_content_content_UserNameLabel for=ctl00_ctl00_ctl00_content_content_content_UserNameTextBox>Sender'susername:</LABEL>
    <input id=ctl00_ctl00_ctl00_content_content_content_UserNameTextBox [email protected] name=ctl00$ctl00$ctl00$content$content$content$UserNameTextBox>



    <LABEL id=ctl00_ctl00_ctl00_content_content_content_PasswordLabel for=ctl00_ctl00_ctl00_content_content_content_PasswordTextBox>Sender'spassword:</LABEL>
    <input id=ctl00_ctl00_ctl00_content_content_content_PasswordTextBox type=password name=ctl00$ctl00$ctl00$content$content$content$PasswordTextBox>


    <input id=ctl00_ctl00_ctl00_content_content_content_NTLMRadioButton onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$ctl00$content$content$content$NTLMRadioButton\',\'\')', 0)" type=radio value=NTLMRadioButton name=ctl00$ctl00$ctl00$content$content$content$Authentication>



    <LABEL for=ctl00_ctl00_ctl00_content_content_content_NTLMRadioButton>NTLM (Windows authentication)</LABEL>
    Choose this option if your e-mail server is on a local area network and you connect to it using windows credentials.
     
  6. I was tearing out what hair I have left until I tried port 587.

    If your config looks exactly like the one above but still doesn't work, you might want to try that. Mine now looks like this:




    <system.net>


    <mailSettings>


    <smtp from="[email protected]">


    <network host="smtp.mydomain.com" userName="[email protected]" password="pass" port="587"></network>


    </smtp>


    </mailSettings>


    </system.net>
    It'staking its own, sweet time to get the message out though... many many minutes before it appears.
     
  7. In general the preferred smtp server to use when using web applications to send out email is 'localhost'. This will use the webservers smtp service to relay out the email. No login/password or port number is required when using 'localhost' as the smtp server.

    rcp
    DiscountASP.NET
    www.DiscountASP.NET
     
  8. Roger that, rcp. Works fine; thanks for that.


    Saving the world, one line of code at a time.
     
  9. actually u don't need to add anything in the web.config file,
    just use this code behind :



    Dim mm As New MailMessage(New MailAddress("[email protected]"), New MailAddress("ToAddress"))
    mm.Subject = "hi"
    mm.Body = "bla bla bla ,, "
    mm.IsBodyHtml = False
    Dim smtp As New SmtpClient
    smtp.Host = "smtp.yourdomain.com"
    smtp.Port = 587
    smtp.UseDefaultCredentials = False
    smtp.Credentials = New NetworkCredential("[email protected]", "password")
    smtp.Send(mm)
     
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