Results 1 to 22 of 22

Thread: how to mail from asp.net 3.5

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    how to mail from asp.net 3.5

    see the code

    Code:
        Dim message As New MailMessage()
                        message.From = New MailAddress("erum@msn.com")
    
                        message.[To].Add(New MailAddress("erum@msncom"))
                        'message.[To].Add(New MailAddress("recipient2@foo.bar.com"))
                        'message.[To].Add(New MailAddress("recipient3@foo.bar.com"))
    
                        'message.CC.Add(New MailAddress("carboncopy@foo.bar.com"))
                        'message.Subject = "This is my subject"
                        message.Body = "This is the content"
    
                        Dim client As New SmtpClient("IRAM-PC")
    
                        client.Send(message)
    i m unable to send email via this code and gives me an exception

    Failure sending mail.

    System.Net.Mail.SmtpException was unhandled by user code
    Message="Failure sending mail."
    Source="System"
    StackTrace:
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    at gfln1.ViewCompany1.Button1_Click(Object sender, EventArgs e) in C:\Users\Iram\Documents\Visual Studio 2008\Projects\gfln1\gfln1\ViewCompany1.aspx.vb:line 108
    at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
    at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    InnerException: System.Net.WebException
    Message="Unable to connect to the remote server"
    Source="System"
    StackTrace:
    at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
    at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
    at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
    at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
    at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
    at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
    at System.Net.Mail.SmtpClient.GetConnection()
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    InnerException: System.Net.Sockets.SocketException
    ErrorCode=10061
    Message="No connection could be made because the target machine actively refused it 2001:0:4137:9e76:3808:bd63:4b4d:74f7:25"
    NativeErrorCode=10061
    Source="System"
    StackTrace:
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
    at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
    InnerException:
    There is no achievement without goals

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: how to mail from asp.net 3.5

    "Dim client As New SmtpClient("IRAM-PC")"

    Do you have an exchange server that is running in your PC?
    If not you must rely on a mail host.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    can u further describe or give me an example code
    There is no achievement without goals

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Hey,

    The problem here is that it wasn't able to connect to an SMTP Server, located at IRAM-PC.

    Is that computer on your network, and do you have permission to access it?

    Can you connect to this SMTP using a third party application first?

    Gary

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    OK , i m using my local pc and using private Internet service ...
    There is no achievement without goals

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Ok, so do you have an SMTP Server running? It does't sound like you have. In which case, you won't be able to send emails.

    Gary

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    thanks gary for all these ,if this is the case i will get back to u on this issue in my later post with certain updates
    There is no achievement without goals

  8. #8
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Sounds like a plan.

    Gary

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    see the link http://www.thesmartcodes.com/a-simpl...-from-asp-net/

    can any one see this and see if it is working if i specify (for example my gmail address and password ,username) in the variable mentioned over there ??

    and lastly called sendMail function just
    There is no achievement without goals

  10. #10
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: how to mail from asp.net 3.5

    last time i checked gmail was working.
    You might want to consider smtpclient EnableSsl and Timeout.
    Sometimes EnableSsl my give you errors with the certificates.I don't think gmail will do that but have it as a future consideration(my previous company needed this to be false for the mail to work).
    Timeout is optional.If your mail fire's right away you can use a low value.The default if i'm not wrong is 1 minute and a half.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    i m not getting any error but no mail sending too
    There is no achievement without goals

  12. #12
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: how to mail from asp.net 3.5

    I assume you are using SSL.
    Try these ports:465 or 25
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    yes i tried with both ports ,non of them working fine,can u run code at ur side(just to check out comptability of port) and check ??
    There is no achievement without goals

  14. #14
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Hey,

    There are lots of different reasons that this could be happening. For instance, your IP address that you are sending from is blacklisted, the emails are going into the junk mail folder, etc, etc.

    Gary

  15. #15
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    its not going to junk mail ,i checked
    There is no achievement without goals

  17. #17
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    As I mentioned, that is just one of the many reasons that the email might not be coming through. Without knowing specifics about your setup, i.e. what SMTP server you are using, whether SSL is enabled, what ports you are using, what email addresses you are sending to, etc (and even then it might be difficult), we are not going to be able to suggest anything else.

    Gary

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    well working fine with following lines of code with gmail to gmail ,let me share on forum

    Code:
     try
            {
                MailMessage mail = new MailMessage();
                mail.To.Add("email_add_of_the_receiver@gmail.com");
                mail.From = new MailAddress(email_of the_sender@yahoo.com);// or could be @gmail.com and etc OR it can be a textbox were you CAN enter your email
                mail.Subject = "Comment/Question";
                string Body = the_textbox_Name_were_you_enter_your_message.text;
                    mail.Body = Body;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential
                  ("email_add_of_the_receiver@gmail.com", "your password");
                smtp.EnableSsl = true;
                smtp.Send(mail);
               
            }
            catch
            {
                
            }
    There is no achievement without goals

  19. #19
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Hello,

    Ok, so this works, which means your code has all the elements that it needs to work.

    Now, what are the exact circumstances that it fails in? Which SMTP Server are you using?

    Gary

  20. #20
    Member
    Join Date
    Mar 2007
    Posts
    37

    Re: how to mail from asp.net 3.5

    salam erum

    Code:
    Dim MESSAGE As New MailMessage
            Dim client As New SmtpClient("smtpout.asia.secureserver.net")
            client.Credentials = New System.Net.NetworkCredential("abc@xyz.com", "abcdef")
    
            client.Port = 25
    
            client.EnableSsl = False
    
            MESSAGE.From = New MailAddress("abc@xyz.com")
            MESSAGE.To.Add(New MailAddress(TextBox1.Text))
    
    
            message.Subject = "abc"
    
            MESSAGE.Body = "abc"
    
            client.Send(MESSAGE)
    Last edited by gep13; Dec 26th, 2010 at 02:52 PM. Reason: Added CODE tags

  21. #21
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: how to mail from asp.net 3.5

    Hello selicon.valley,

    The code that you have posted will work in the simplest of cases, however, certain SMTP Servers are more complicated than this, using different ports, settings, etc.

    I think this is the problem that the OP is having, and why I asked for the exact situation that this are in.

    Gary.

    P.S. I have edited your post to include [CODE][/CODE] tags, as this makes it much easier to read code posted into the forums.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to mail from asp.net 3.5

    walikum salam selicon.valley

    can u send me the code that u have in working form in asp.net 3.5 .remember i m using admin account of website, rather than yahoo,hotmail ,google.
    There is no achievement without goals

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width