Lunarpages Web Hosting Forum

Author Topic: Mail from asp.net form  (Read 9308 times)

Offline biffwa57

  • Newbie
  • *
  • Posts: 2
Mail from asp.net form
« on: July 21, 2007, 09:38:00 AM »
I've been trying countless hours to get email from my asp.net form.  Tech support offered no help.   
I've set up a subdomain for a site I am building, the email account is under the main domain.  I have yet to get this to connect to the server.  Here's the code I've been using.

 Dim iMsg
            Dim iConf
            Dim Flds
            Dim strHTML
            Dim strBody
            Dim strSmartHost
            Const cdoSendUsingPort = 465
            strSmartHost = "mail.maindomain.us"
            iMsg = CreateObject("CDO.Message")
            iConf = CreateObject("CDO.Configuration")
            Flds = iConf.Fields
            With Flds
                .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
                .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
                .Item("http://schemas.microsoft.com/cdo/configuration/sendusername", "emailaccount@domain")
                .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password")
                .Update()
            End With
            strBody = "This is a test of sending an email via ASP" & vbCrLf & vbCrLf
            strBody = strBody & "This is line 2. " & vbCrLf
            strBody = strBody & "you can have as many as you want" & vbCrLf
            strBody = strBody & "THIS IS AN AUTOMATED EMAIL - PLEASE DO NOT REPLY"
            ' apply the settings to the message
            With iMsg
                .Configuration = iConf
                .To = "externalemailacct"
                .From = "emailaccount"
                .Subject = "This is a test message from an ASP Email"
                .textbody = strBody
                'redirect code goes here
                .Send(iMsg)
            End With
            ' cleanup of variables
            iMsg = Nothing
            iConf = Nothing
            Flds = Nothing

I've tried using different ports, encoded and unecoded username and password.
If I don't get this to work soon, I will have to try another hosting company.

biffwa57

Offline schildog

  • Newbie
  • *
  • Posts: 1
Re: Mail from asp.net form
« Reply #1 on: July 29, 2007, 02:46:33 PM »
I've been working on this same problem and, like you, got very little help from the helpdesk. Some research and a lucky guess got me to this:

host = 'localhost'
port = '25'

which worked! I had also included username and password credentials but found that it didn't make a difference if I used them or not.

Let me know if you would like any more detail or code examples. Good luck!

Offline wannall

  • Newbie
  • *
  • Posts: 5
Re: Mail from asp.net form
« Reply #2 on: August 15, 2007, 08:48:49 AM »
I would love more detail about getting email working from our ASP.NET.  Similarly, I have had little success with support.

I have hunted for smtp settings I should use in my web.config.  I found some in a help page that I have never found again, but it matters little.  No variation of what I found worked.

Everything I read about hosting at LunarPages says that we get smtp mail server access with our hosting.  ALL hosting plans.  I just need the web.config settings to use that give me access to System.Net.Mail methods.

Current exact problem:  We use built-in membership provider objects in our app based on The Beer House.  Our users need to reset passwords from the original password we assign them.  they can reset the password, but the email will not go out, and I cannot find a way to interrupt the reset process and send email using CDOSYS, which is the only method I can get any description of from the support staff.

I must be missing something terribly obvious and simple, and I will happily blush with embarrassment the moment someone shows me what it is.

If you know the settings, please post same.

Thanks.

Offline gohickey

  • Intergalactic Cowboy
  • *****
  • Posts: 55
Re: Mail from asp.net form
« Reply #3 on: August 15, 2007, 08:54:33 AM »
The built-in membership provider sends mail just fine for me - here is what is in my web.config for it:

     <mailSettings>
         <smtp from="info@mydomain.com">
            <network host="mail.mydomain.com" password="mypass" userName="info@mydomain.com"/>
         </smtp>
      </mailSettings>

Offline wannall

  • Newbie
  • *
  • Posts: 5
Re: Mail from asp.net form
« Reply #4 on: August 15, 2007, 11:41:36 AM »
Yahoo!!!!!!!!!

Your settings plus one other piece of info got us going:  the user@domain.com has to be s webmail user established in our domain.  I was trying to use our domain login.  I don't know if the user HAS to be a webmail user.  There may be some other description of what's needed, but I do know that using your version of the web.config settings and supplying a webmail user and that user's password did the trick.

Thank you both for making it clear that it should work the way it seemed and for providing a working example know to work. 

Problem solved!

Offline BusinessHut

  • Newbie
  • *
  • Posts: 4
Re: Mail from asp.net form
« Reply #5 on: January 25, 2009, 07:50:59 PM »
Here's a configuration that works for me:

Code: [Select]
    <system.net>
        <mailSettings>
            <smtp>
                <network
                  host="localhost"   
                  port="25"
                  userName="realEmailAccount@mySite.com"
                  password="PlainTextPasswordsAreDangerous"
                  />
            </smtp>
        </mailSettings>
    </system.net>

Offline vks87

  • Intergalactic Cowboy
  • *****
  • Posts: 60
Re: Mail from asp.net form
« Reply #6 on: March 12, 2009, 10:46:53 PM »
Actually i don't have any information about asp.net so your every post related with asp.net ll be beneficial for me.These posts are also very nice for me..good work guys..

Offline adults

  • Newbie
  • *
  • Posts: 5
Re: Mail from asp.net form
« Reply #7 on: April 18, 2009, 05:27:17 PM »
Send mail code:
 
public static void Sendmail(string email, string title, string content)
    {



        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        string username = System.Web.Configuration.WebConfigurationManager.AppSettings["username"].ToString();
        string password = System.Web.Configuration.WebConfigurationManager.AppSettings["password"].ToString();
        string smtp = System.Web.Configuration.WebConfigurationManager.AppSettings["smtp"].ToString();
        string mail = System.Web.Configuration.WebConfigurationManager.AppSettings["mail"].ToString();
        string port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToString();


        MailAddress fromAddress = new MailAddress(mail, "mail from xx");
        smtpClient.Host = smtp;
        NetworkCredential nc = new NetworkCredential(username, password);
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = nc;
        smtpClient.Port = int.Parse(port);
        message.From = fromAddress;
        message.To.Add(email);
        message.Subject = title;
        message.IsBodyHtml = true;
        message.Body = content;
        smtpClient.Send(message);


    }