0 votes

I just want to check an email and if the title matches forward it to someone.

We use o365 and when i try the following it times out;

smtp.Connect("smtp.office365.com");
smtp.StartTLS();

I have also tried

smtp.ConnectSSL("smtp.office365.com",587);
smtp.StartTLS();

and i get the error message Limilabs.Client.ServerException: 'Authenticate as SSL/TLS client failed.

I tried adding the tls12 but that didnt work either

by (200 points)

1 Answer

0 votes

1.
Don't mix ConnectSSL and StartTLS.

2.
Port 587 is not for implicit SSL - don't use ConnectSSL with this port.

3.
Outlook365 SMTP server requires explicit SSL – use Connect and StartTLS method:

using (Smtp client = new Smtp ())
{
    client.Connect("smtp.office365.com");
    client.StartTLS();

    client.UseBestLogin("user@domain.onmicrosoft.com", "password");
    ...
}
by (276k points)
this seemed to work, when I look at the sent items I see the email in that folder, however, the recipient doesn't get it into his inbox
Please remember to examine the result of SendMessage method.

You may also turn on logging to examine client-server communication:
https://www.limilabs.com/blog/logging-in-mail-dll
Mail.dll Information: 0 :  1 14:03:30 3.0.20308.1141
Mail.dll Information: 0 :  1 14:03:30 Checking if license file is present.
Mail.dll Information: 0 :  1 14:03:30 License file present. Loading license file.
Mail.dll Information: 0 :  1 14:03:30 License file loaded. Loading xml.
Mail.dll Information: 0 :  1 14:03:30 Xml loaded. Getting public key.
Mail.dll Information: 0 :  1 14:03:30 Public key acquired. Checking license signature.
Mail.dll Information: 0 :  1 14:03:30 Signature valid. Checking if license xml is valid.
Mail.dll Information: 0 :  1 14:03:30 License xml file is valid ('TC Industries of Canada Company'). Checking product name.
Mail.dll Information: 0 :  1 14:03:30 Product name is valid. Checking product version.
Mail.dll Information: 0 :  1 14:03:30 Product version is valid. Checking if license is revoked.
Mail.dll Information: 0 :  1 14:03:30 License status is valid.
Mail.dll Information: 0 :  1 14:03:30 Connecting to 'smtp.office365.com:587', SSL/TLS: False.
Mail.dll Information: 0 :  1 14:03:30 S: 220 YT1PR01CA0061.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 23 Dec 2020 19:03:29 +0000
Mail.dll Information: 0 :  1 14:03:30 C: EHLO [192.168.100.14]
Mail.dll Information: 0 :  1 14:03:30 S: 250-YT1PR01CA0061.outlook.office365.com Hello [24.114.29.242]
Mail.dll Information: 0 :  1 14:03:30 S: 250-SIZE 157286400
Mail.dll Information: 0 :  1 14:03:30 S: 250-PIPELINING
Mail.dll Information: 0 :  1 14:03:30 S: 250-DSN
Mail.dll Information: 0 :  1 14:03:30 S: 250-ENHANCEDSTATUSCODES
Mail.dll Information: 0 :  1 14:03:30 S: 250-STARTTLS
Mail.dll Information: 0 :  1 14:03:30 S: 250-8BITMIME
Mail.dll Information: 0 :  1 14:03:30 S: 250-BINARYMIME
Mail.dll Information: 0 :  1 14:03:30 S: 250-CHUNKING
Mail.dll Information: 0 :  1 14:03:30 S: 250 SMTPUTF8
Mail.dll Information: 0 :  1 14:03:30 C: STARTTLS
Mail.dll Information: 0 :  1 14:03:30 S: 220 2.0.0 SMTP server ready
Mail.dll Information: 0 :  1 14:03:30 C: EHLO [192.168.100.14]
Mail.dll Information: 0 :  1 14:03:30 S: 250-YT1PR01CA0061.outlook.office365.com Hello [24.114.29.242]
Mail.dll Information: 0 :  1 14:03:30 S: 250-SIZE 157286400
Mail.dll Information: 0 :  1 14:03:30 S: 250-PIPELINING
Mail.dll Information: 0 :  1 14:03:30 S: 250-DSN
Mail.dll Information: 0 :  1 14:03:30 S: 250-ENHANCEDSTATUSCODES
Mail.dll Information: 0 :  1 14:03:30 S: 250-AUTH LOGIN XOAUTH2
Mail.dll Information: 0 :  1 14:03:30 S: 250-8BITMIME
Mail.dll Information: 0 :  1 14:03:30 S: 250-BINARYMIME
Mail.dll Information: 0 :  1 14:03:30 S: 250-CHUNKING
Mail.dll Information: 0 :  1 14:03:30 S: 250 SMTPUTF8
Mail.dll Information: 0 :  1 14:03:30 C: AUTH LOGIN
Mail.dll Information: 0 :  1 14:03:30 S: 334 VXNlcm5hbWU6
Mail.dll Information: 0 :  1 14:03:30 C: Xxxx
Mail.dll Information: 0 :  1 14:03:30 S: 334 UGFzc3dvcmQ6
Mail.dll Information: 0 :  1 14:03:30 C: Xxxx
Mail.dll Information: 0 :  1 14:03:31 S: 235 2.7.0 Authentication successful

From this log it looks like it should be ok, not sure why its not coming into the inbox
This log shows authentication only. You are not sending any messages.
Mail.dll Information: 0 :  1 14:17:17 C: MAIL FROM:<AAAA@tcindustries.com>
Mail.dll Information: 0 :  1 14:17:17 C: RCPT TO:<BBBB@tcindustries.com>
Mail.dll Information: 0 :  1 14:17:17 C: NOOP
Mail.dll Information: 0 :  1 14:17:18 S: 250 2.1.0 Sender OK
Mail.dll Information: 0 :  1 14:17:18 S: 250 2.1.5 Recipient OK
Mail.dll Information: 0 :  1 14:17:18 S: 250 2.0.0 OK
Mail.dll Information: 0 :  1 14:17:18 C: BDAT 63319 LAST
Mail.dll Information: 0 :  1 14:17:18 C (63319 bytes):
Mail.dll Information: 0 :  1 14:17:18 Received: from [192.168.100.14] (24.114.29.242) by
 YTOPR0101CA0033.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:15::46) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.27 via Frontend
 Transport; Wed, 23 Dec 2020 18:51:55 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YTBPR01CA0033.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::46) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 18:23:23 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YT1PR01CA0034.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01::47) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 16:45:04 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YT1PR01CA0137.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::16) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 16:30:24 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YTXPR0101CA0002.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00::15) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 16:18:15 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YT1PR01CA0131.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::10) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 16:07:39 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YTOPR0101CA0001.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:15::14) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.27 via Frontend
 Transport; Wed, 23 Dec 2020 15:27:40 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YT1PR01CA0082.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::21) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 15:18:08 +0000
Received: from [192.168.100.14] (24.114.29.242) by
 YTXPR0101CA0016.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00::29) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3700.27 via Frontend Transport; Wed, 23 Dec 2020 15:11:42 +0000
Received: from DM6PR14MB3452.namprd14.prod.outlook.com (2603:10b6:5:1ef::17)
 by DM5PR1401MB2060.namprd14.prod.outlook.com with HTTPS; Wed, 16 Dec 2020
 21:07:09 +0000
Received: from DM5PR1401MB2060.namprd14.prod.outlook.com (2603:10b6:4:52::14)
 by DM6PR14MB3452.namprd14.prod.outlook.com (2603:10b6:5:1ef::17) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12; Wed, 16 Dec
 2020 21:07:09 +0000
Received: from DM5PR1401MB2060.namprd14.prod.outlook.com
 ([fe80::f0fd:4542:800c:82ba]) by DM5PR1401MB2060.namprd14.prod.outlook.com
 ([fe80::f0fd:4542:800c:82ba%5]) with mapi id 15.20.3654.025; Wed, 16 Dec 2020
 21:07:09 +0000
Received: from TCCANADA.TCIC.COM (24.114.29.242) by YTXPR0101CA0038.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Wed, 16 Dec 2020 21:07:08 +0000
From: TCIC SCADA <AAAA@tcindustries.com>
Subject: Elevated Temperature Alert
Thread-Topic: Elevated Temperature Alert
Thread-Index: AQHW0+9qKnjDqGSkTUKD5zpXe+D7eA==
Date: Wed, 16 Dec 2020 16:07:08 -0500
Message-ID:
 <DM5PR1401MB2060FB325D36C7B5846E7B2EF9C50@DM5PR1401MB2060.namprd14.prod.outlook.com>
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-clientproxiedby: YTXPR0101CA0038.CANPRD01.PROD.OUTLOOK.COM
 (2603:10b6:b00:1::15) To DM5PR1401MB2060.namprd14.prod.outlook.com
 (2603:10b6:4:52::14)
authentication-results: tcindustries.com; dkim=none (message not signed)
 header.d=none;tcindustries.com; dmarc=none action=none
 header.from=tcindustries.com;
x-originating-ip: [24.114.29.242]
x-ms-office365-filtering-correlation-id: ee59368a-49ba-4ba1-e732-08d8a2068cea
x-ms-traffictypediagnostic: DM6PR14MB3452:
x-ms-oob-tlc-oobclassifiers: OLM:5797;
x-microsoft-antispam: BCL:0;
x-forefront-antispam-report:
 CIP:255.255.255.255;CTRY:;LANG:en;SCL:-1;SRV:;IPV:NLI;SFV:SKI;H:DM5PR1401MB2060.namprd14.prod.outlook.com;PTR:;CAT:NONE;SFS:;DIR:INB;
x-ms-exchange-antispam-messagedata:
This is also cut.

There's no need to paste entire log. Examine the SendMessage response. Or the last server response.

You may also send the log to our support email ( https://www.limilabs.com/support ).

However if your server accepts the message you'll need to consult your administrator (or maybe it just goes to spam?).
Thank you for your help, I have it running.  

If I need to forward it to multiple email addresses (below works for a single email)

builder.[To].Add(New MailBox("gr****@tcindustries.com", "Gr****"))
You can use Add method multiple times -or- use AddRange instead.
...