|
I'm having trouble using TLS1.2 with smtp.gmail.com and authenticating; gmail keeps saying that I'm not authenticating correctly.
Not sure if I'm using the ServicePointManager correctly at this point.
So I'm using smtp.gmail.com on port 587 with ssl enabled.
This is what I have. The SmtpClient runs first and picks up the credentials, the the SendEmailAsync runs and sends. The Catch catched the exception saying that I wasn't authenticated.
Scratching my head on this.
public static SmtpClient create_SMTPClient(smtp_credentials smtpC)
{
var smtpClient = new SmtpClient();
var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
if (smtpSection == null)
{
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
<pre>
var smtpCredentials = new System.Net.NetworkCredential() {
UserName = smtpC.smtp_AccountName,
Password = smtpC.smtp_Password
};
smtpClient.Credentials = smtpCredentials;
smtpClient.Host = smtpC.smtp_ServerUrl;
smtpClient.Port = smtpC.smtp_PortNumber;
smtpClient.EnableSsl = smtpC.smtp_PortNumber == 587 ? true : false;
smtpClient.Timeout = 250000;
}
if (smtpClient.Port == 587)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
if (smtpClient.Port == 443)
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidation_Callback;
return smtpClient;
}
public static async Task<SendEmailCompletedEventArgs> sendEmailAsync(SmtpClient smtpClient, MailMessage message, int retryCount)
{
int currentTry = 0;
while ((currentTry < retryCount))
{
try
{
await smtpClient.SendMailAsync(message);
return new SendEmailCompletedEventArgs(null, false, null, currentTry);
}
catch (Exception ex)
{
currentTry++;
if ((currentTry >= retryCount))
{
return new SendEmailCompletedEventArgs(ex, true, null, currentTry);
}
}
}
return new SendEmailCompletedEventArgs(null, true, null, currentTry);
}</pre>
If it ain't broke don't fix it
|
|
|
|
|
I think my issue here is I need to connect as TLS1.2 but it's connecting as TLS1.1, in which Gmail considers to be less secure.
So the Service point stepped down a notch and my code failed.
So I wonder if it's a cipher in my registry on SChannel or my protocols that I selected.
If it ain't broke don't fix it
|
|
|
|
|
Which OS? TLS1.2 was disabled by default prior to 8.1 / 2012 R2, and not available on Vista / 2008 or earlier.
You should be able to check whether it's enabled from the IE options dialog, on the "Advanced" page:
Support for SSL/TLS protocols on Windows – Unleashed[^]
AFAIK, those settings also affect .NET code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Developing on Win10 with VS2017.
I program the ServicePointManager, and in the SmtpClient it says the address threw an exception before I even call SendMailAsync
The after the SendMailAsync runs, the caught Exception says must StartTLS first.
My endpoint is smtp.gmail.com on 587 with ssl on and using .Net 4.6.1
Strange, but after calling SendEmailAsync, it reads the SmtpCreddentials again and call Send a 2nd time.
I think it works in my VB version using .Net 4.6.1
If it ain't broke don't fix it
|
|
|
|
|
I changed my Gmail account type to less secure and it works fine with the same settings.
I wonder what the difference is between secure and less secure, I mean the whole difference is.
I hear .Net 4.6.2 is suppose to fix this for secure app.
If it ain't broke don't fix it
|
|
|
|
|
how to make calculation based on the quantity that user key in with the data(column) in the excel file that we link in c# ?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok. sorry 4 that. i just think maybe some of u have example that can be shared
|
|
|
|
|
It's possible we do - but if we have no idea what you are talking about (because you gave us no information) then it's unlikely that we can tell you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I'm trying to learn Rx. I have seen a lot of Google results and other resources pointing to this site.
Thing is, I'm just not getting it. What I'd really like to see is a simple, real world example. The code snippets in that site are VERY brief, not too deeply explained, and don't really show real work usage.
Does anyone know of any tutorials or real world usage examples of Rx?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi,
I can't help you, but maybe this can.
|
|
|
|
|
Already did that
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I would recommend starting off here before delving into the Rx book.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
|
Kevin Marois wrote: What I'd really like to see is a simple, real world example
My guess is that is an oxymoron.
If it is simple and you are using reactive extensions then someone is experimenting and not writing good code. It should rather be the case that there is a complex problem that needs a solution and reactive extensions are thus needed (in very limited cases.)
|
|
|
|
|
Hi. I want to know is it possible to play audio though online storage.
I have my website and I see am able to play music from my website form of my server storage what I transfer with filezilla.
I want to know can I do this using winforms
If so is there a source or a link
Thanks
|
|
|
|
|
AnthonyRaven wrote: is it possible to play audio though online storage. That does not really make sense. You play audio through a music application on your PC, reading the audio stream from disk or other connected device. Also what is the connection in your question between your website and a Windows Forms application?
|
|
|
|
|
i have a demo program of Rfid Reader ,from which i saw the commands to be sent to rfid reader in order to initialize rfid reader.and that program is sending 2 commands to Rfid Reader continously ..and the rfid reader is sending response command continously ... i achieve this part ,and i am receiving response command in command prompt . ,. now when i placed a tag in front of rfid reader ,rfid reader detected the tag and send this 33 bytes to command prompt .. how i get the number from 00 00 to 67 (middle portion) , as this is the Epc (Electronic Product code) .i want to get this number and Epcs of other tags also . how can i achieve this ?I have to send these EPCs on Firebase Database .I am stuck here .what i should do now ?
33 bytes
A0-13-01-89-0C-34-00-00-00-00-00-00-00-00-00-00-00-36-67-4B-9B-A0-01-89-00-00-11-00-00-00-01-BA
|
|
|
|
|
|
Hi, Good Evening everyone
I have created two classes namely Shape, Rectangle with Draw() method in both the classes, Rectangle class is a deried class from Shape. I have declared a public variable in Rectangle called num and initialised a value to it.
In the main class I have created an object of type class in following manner.
Shape s = new Rectangle();
Now when I am trying to access num variable of rectangle class it gives error saying “ /Users/apple/Projects/Practice/Practice/Program.cs(33,33): Error CS1061: 'Shape' does not contain a definition for 'num' and no extension method 'num' accepting a first argument of type 'Shape' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Practice)”
My Understanding : The statement new Rectangle(); creates an object of type Rectangle in the memory and its reference is stored in object s of type Shape. So the object s should have access to variable num defined in rectangle class. Please make me understand this concept why we can’t access num variable from Object of type Shape.
Pls find the attached screenshot.
modified 8-Jul-17 13:10pm.
|
|
|
|
|
Because it doesn't exist in Shape.
If I have a toy, my son can play with it. But I can't play with my son's toy.
modified 8-Jul-17 13:24pm.
|
|
|
|
|
Member 13299953 wrote: My Understanding : The statement new Rectangle(); creates an object of type Rectangle in the memory and its reference is stored in object s of type Shape. So the object s should have access to variable num defined in rectangle class. Please make me understand this concept why we can’t access num variable from Object of type Shape.
Wrong. Shape only know what's defined in the Shape class. It knows absolutely nothing about any class that inherits from it.
The reverse is also true. Rectangle knows ONLY what Shape exposes to it since it's inheriting from Shape and what's defined in the Rectangle class. Private members defined in Shape are not visible to Rectangle at all.
Inheritance only goes one way. A base class can NOT and should not know anything at all about the classes that inherit from it.
|
|
|
|
|
So, let's assume you have this:
public class Shape
{
public virtual void Draw()
{
Console.WriteLine("Drawing in Shape");
}
}
public class Rectangle : Shape
{
public int Ratio { get; set; }
public override void Draw()
{
Console.WriteLine("Drawing in Rectangle");
}
}
public class Circle : Shape
{
public int Radius { get; set; }
public override void Draw()
{
Console.WriteLine("Drawing in Circle");
}
}
When you write this:
Shape s = new Rectangle();
s.Draw(); It works; this prints:
Drawing in Rectangle Because the system "knows" that the object instance that s refers to is a Rectangle when it looks at runtime to find the most appropriate method.
Similarly, this:
Shape s2 = new Circle();
s2.Draw(); will print:
Drawing in Circle Becuase it looks at that for the Circle version of the method.
But ... s is a Shape, so it can refer to one of three classes: Shape, Rectangle, or Circle, so if you write
Console.Writeline("{0}", s.Ratio); Or
Console.Writeline("{0}", s.Radius); What can the system do? If s contains a reference to a Rectangle, the first code is fine, but the second fails, and if s contains a Circle then the first fails, and the second succeeds - if s has a Shape, then they both fail!
When you declare a variable, what you can do with it depends on the type of the variable, not what it contains. And because s is a Shape, you can only access Shape methods, fields, and properties via it. Declare your variable as the appropriate type, and you can do what you need:
Rectangle r = new Rectangle();
Circle c = new Circle();
Shape s = r;
s.Draw();
s = c;
s.Draw();
Console.WriteLine("{0}", r.Ratio);
Console.WriteLine("{0}", c.Radius);
Make sense now?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
C# provides flexible ways to constrain a Class to being a provider of data, and methods, to other Classes that inherit from it. These include virtual Methods, abstract Classes, and Interfaces. The inheriting instances of a Class have special semantics for declaring their members that implement the inherit-from Class' members: the use of 'override, and 'new.
If you are confused by this wealth of possibilities, do not feel alone It takes most folks time and effort to master them, and choose which techniques are most useful in a given circumstance/problrm/scenario.
OriginalGriff's example uses a virtual method in a Public Class; in that example you could create an instance of 'Shape using 'new.
A further constraint can be achieved using an abstract Class: you cannot create an instance of an abstract Class. In your case, I think 'Shape is, indeed, an abstraction, and, creating an instance of it would have no purpose.
An example of using an abstract Class:
public abstract class Shape
{
public virtual void Draw(string txt = "Shape")
{
Console.WriteLine(txt);
}
}
public class Rect : Shape
{
public string Name = "Rect";
public int Ratio { get; set; }
public void Draw(String txt = "Rect")
{
base.Draw(txt);
}
}
public class Circle : Shape
{
public string Name = "Circle";
public int Radius { get; set; }
public void Draw(String txt = "Circle")
{
base.Draw(txt);
}
} Let's test this:
Rect newRectangle = new Rect();
Circle newCircle = new Circle();
newRectangle.Draw();
newCircle.Draw();
Shape shapeAsRectangle = newRectangle;
Shape shapeAsCircle = newCircle;
shapeAsRectangle.Draw();
shapeAsCircle.Draw();
Rect rectBackFromShape = shapeAsRectangle as Rect;
Circle rectBackFromCircle = shapeAsCircle as Circle;
rectBackFromShape.Draw();
rectBackFromCircle.Draw();
Console.WriteLine(newRectangle == shapeAsRectangle);
Console.WriteLine(newCircle == shapeAsCircle);
Console.WriteLine(newRectangle == rectBackFromShape);
Console.WriteLine(newCircle == rectBackFromCircle); Notes:
0. to be used by inheriting classes this method in the abstract class must be 'public, which means it can be called on an instance of an inheriting class down-cast to the abstract parent's Type. imho, this is less than ideal.
1. even though we can't create an instance of an abstract class, we can "change the view" we have by casting it to its abstract base Type ... when cast, the data, or methods, specific to the inherited class are not "lost" !
2. here you see we can re-hydrate an instance cast to its abstract base Type back to its "native" Type, and, now we have access again to its data, and methods.
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy
|
|
|
|