Click here to Skip to main content
15,887,453 members
Home / Discussions / C#
   

C#

 
SuggestionRe: Paste CF_ENHMETAFILE=14 image file Pin
Richard MacCutchan14-Jul-17 20:35
mveRichard MacCutchan14-Jul-17 20:35 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
manuellopes15-Jul-17 6:08
manuellopes15-Jul-17 6:08 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
Richard MacCutchan15-Jul-17 6:22
mveRichard MacCutchan15-Jul-17 6:22 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
manuellopes15-Jul-17 6:33
manuellopes15-Jul-17 6:33 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
Richard MacCutchan15-Jul-17 6:53
mveRichard MacCutchan15-Jul-17 6:53 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
manuellopes15-Jul-17 7:38
manuellopes15-Jul-17 7:38 
GeneralRe: Paste CF_ENHMETAFILE=14 image file Pin
Richard MacCutchan15-Jul-17 20:30
mveRichard MacCutchan15-Jul-17 20:30 
QuestionServicePointManager and TLS1.2 with Gmail Pin
jkirkerx13-Jul-17 6:34
professionaljkirkerx13-Jul-17 6:34 
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;
        }

        // Shift the encryption level higher for gMail and others
        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);
                }
            }

        }

        //  Code should never reach here, but without this line you'll get a BC42105 warning:
        return new SendEmailCompletedEventArgs(null, true, null, currentTry);
    }</pre>
If it ain't broke don't fix it

AnswerServicePoint, Address = 'smtpClient.ServicePoint.Address' threw an exception of type 'System.NotSupportedException', Pin
jkirkerx13-Jul-17 8:45
professionaljkirkerx13-Jul-17 8:45 
GeneralRe: ServicePoint, Address = 'smtpClient.ServicePoint.Address' threw an exception of type 'System.NotSupportedException', Pin
Richard Deeming13-Jul-17 9:52
mveRichard Deeming13-Jul-17 9:52 
GeneralRe: ServicePoint, Address = 'smtpClient.ServicePoint.Address' threw an exception of type 'System.NotSupportedException', Pin
jkirkerx13-Jul-17 11:38
professionaljkirkerx13-Jul-17 11:38 
GeneralRe: ServicePoint, Address = 'smtpClient.ServicePoint.Address' threw an exception of type 'System.NotSupportedException', Pin
jkirkerx13-Jul-17 12:14
professionaljkirkerx13-Jul-17 12:14 
Questionhye :) Pin
Member 1330557812-Jul-17 17:24
Member 1330557812-Jul-17 17:24 
AnswerRe: hye :) Pin
OriginalGriff12-Jul-17 20:23
mveOriginalGriff12-Jul-17 20:23 
GeneralRe: hye :) Pin
Member 1330557812-Jul-17 22:14
Member 1330557812-Jul-17 22:14 
GeneralRe: hye :) Pin
OriginalGriff12-Jul-17 22:36
mveOriginalGriff12-Jul-17 22:36 
AnswerRe: hye :) [Repost] Pin
Richard MacCutchan12-Jul-17 22:28
mveRichard MacCutchan12-Jul-17 22:28 
QuestionRx - Reactive Extensions Pin
Kevin Marois12-Jul-17 6:59
professionalKevin Marois12-Jul-17 6:59 
AnswerRe: Rx - Reactive Extensions Pin
Luc Pattyn12-Jul-17 8:02
sitebuilderLuc Pattyn12-Jul-17 8:02 
GeneralRe: Rx - Reactive Extensions Pin
Kevin Marois12-Jul-17 8:03
professionalKevin Marois12-Jul-17 8:03 
AnswerRe: Rx - Reactive Extensions Pin
Meshack Musundi12-Jul-17 10:45
professionalMeshack Musundi12-Jul-17 10:45 
AnswerRe: Rx - Reactive Extensions Pin
Kenneth Haugland13-Jul-17 13:13
mvaKenneth Haugland13-Jul-17 13:13 
AnswerRe: Rx - Reactive Extensions Pin
jschell15-Jul-17 7:41
jschell15-Jul-17 7:41 
Questionplaying media from server storage help.. in C# Pin
AnthonyRaven11-Jul-17 17:10
AnthonyRaven11-Jul-17 17:10 
AnswerRe: playing media from server storage help.. in C# Pin
Richard MacCutchan11-Jul-17 21:42
mveRichard MacCutchan11-Jul-17 21:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.