?
Solved

How to set mail credentials

Posted on 2011-04-23
14
Medium Priority
?
756 Views
Last Modified: 2012-05-11
I am trying to send mail from my site host. This worked until I changed to  a different site host.

 //send the message
        SmtpClient smtp = new SmtpClient("smtp.stockpickermax.com", 8889);
             
        if (strConnection.Contains("StockProSQL")) // Local server
        {
            // do not send mail;
        }
        else // Remote server
        {
            smtp.UseDefaultCredentials = true;
            smtp.Send(mail);
        }

Error:

No connection could be made because the target machine actively refused it 64.79.170.142:8889

Line 184:        {
Line 185:            smtp.UseDefaultCredentials = true;
Line 186:            smtp.Send(mail);
Line 187:        }
Line 188:        conStockSelect.Close();

Source File: e:\web\stockpicker\htdocs\ErrorHandling\ShowError.aspx.cs    Line: 186

I know the credentials. How can I enter them/

Thanks,

0
Comment
Question by:Dovberman
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 4

Accepted Solution

by:
malikirfan28 earned 1000 total points
ID: 35452891
you can use NetworkCredential to pass the credentials like

smtp.Credentials = new System.Net.NetworkCredential(userName, password)
0
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 1000 total points
ID: 35452902
Try this. I converted it from VB, but it should be close.
System.Net.NetworkCredential networkCredentials = new System.Net.NetworkCredential("xxx@gmail.com", "password");
smtp.UseDefaultCredentials = False;  
smtp.Credentials = networkCredentials;

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35452904
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dovberman
ID: 35453179
This is close. Here is the most recent error:

Compiler Error Message: CS0246: The type or namespace name 'NetworkCredential' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

 

Line 184:        else // Remote server
Line 185:        {
Line 186:            smtp.Credentials = new NetworkCredential("stockpicker", "1088Delb");
Line 187:            smtp.Send(mail);
Line 188:        }

How do I define the NetworkCredential class. This is probably in a using statement.

Thanks,
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35453243
Add System.Net In a Using directive, or try it with the full namespace:

smtp.Credentials = new System.Net.NetworkCredential("stockpicker", "1088Delb");

Also, set default credentials to false:

smtp.UseDefaultCredentials = False;
0
 

Author Comment

by:Dovberman
ID: 35453363
using System.Net.Mail;
using System.Net.NetworkInformation;

No connection could be made because the target machine actively refused it 64.79.170.142:8889
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.Sockets.SocketException: No connection could be made because the target machine actively refused it 64.79.170.142:8889

Source Error:


Line 184:            smtp.UseDefaultCredentials = false;
Line 185:            smtp.Credentials = new System.Net.NetworkCredential("stockpicker", "1088Delb");
Line 186:            smtp.Send(mail);
Line 187:        }
Line 188:        conStockSelect.Close();

I will contact my site provider.

Thanks,

Source File: e:\web\stockpicker\htdocs\ErrorHandling\ShowError.aspx.cs    Line: 186

0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35453521
Maybe the server requires SSL?

smtp.EnableSsl = true;  
smtp.Port = "587";

Set port number as required.  
0
 

Author Comment

by:Dovberman
ID: 35453656
This is the answer from my site host:

I'm afraid Network Credentials are not supported in our environment. You will either have to use "localhost" with no authentication to send out email, or use your email servers address with a valid email address and password for authentication.

How would I implement this?

I am using Outlook 2010.

Thanks,

Dovberman
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35453724
If you are not concerned about who the sent emails are coming from, you could send through a free email account like gmail. The server would then be smtp.gmail.com, ssl enabled, port 587. Supply the credentials the same way.
0
 

Author Comment

by:Dovberman
ID: 35453742
Thanks,

I will try it tomorrow.
0
 
LVL 4

Expert Comment

by:malikirfan28
ID: 35453849
As per answer of your site host. You can use following code to generate email using your hosted server.

 using System.Web.Mail;
.
.
.
MailMessage xMailMessage = new MailMessage();
xMailMessage.From = "test@test.com";
xMailMessage.To = "to@test.com";
xMailMessage.Subject = "This is a test";
xMailMessage.BodyFormat = MailFormat.Html;
xMailMessage.Body = "<html><head><title>Test emial</title></head><br /><br /><hr>JUST A TEST<hr><br /><br /></body></html>";

SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(xMailMessage); 

Open in new window

0
 
LVL 4

Expert Comment

by:malikirfan28
ID: 35453859
You can also use SmtpMail.SmtpServer = "127.0.0.1";
instead of "localhost".
I am sure it will work in your environment.
0
 

Author Comment

by:Dovberman
ID: 35457195
This is what finally worked:

               SmtpClient smtp = new SmtpClient("smtp.stockpickermax.com", 25);
                NetworkCredential Credentials = new NetworkCredential("support@stockpickermax.com", "mypassword");
                smtp.Credentials = Credentials;
                 smtp.Send(mail);
0
 

Author Closing Comment

by:Dovberman
ID: 35457205
Thanks,
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question