Harbour hb_SendMail() Issue

225 views
Skip to first unread message

Ash

unread,
Mar 10, 2025, 2:43:48 PMMar 10
to Harbour Users
Hello Everyone,

I am unable to send emails from a Harbour application I have been using for years. My initial investigation was focused on a critical review of the code that uses hb_SendMail() but found no issues there. However I later found from log files that 'SMTP servers no longer accepting basic authentication' is the cause.

As I haven't a clue for solving this issue, can someone please help. Thank you.

Regards,
Ash

Gerald Drouillard

unread,
Mar 10, 2025, 3:55:52 PMMar 10
to harbou...@googlegroups.com
Basic Auth is being dropped by some companies.  You may be able to add "rules" based on IP addresses.  We have modified hb_sendmail to use curl as the backend.  Here is what deepseek says about curl and smtp:
`curl` supports several types of SMTP authentication methods when sending emails via the SMTP protocol. The specific authentication methods supported by `curl` for SMTP include:

1. **PLAIN**: This is a simple authentication method where the username and password are sent in plain text (base64 encoded). It is straightforward but not secure unless used over a secure connection (TLS/SSL).

2. **LOGIN**: Similar to PLAIN, the LOGIN method also sends the username and password in plain text (base64 encoded). It is another basic authentication method.

3. **CRAM-MD5**: This method provides a challenge-response authentication mechanism that uses a cryptographic hash function (MD5) to avoid sending the password in plain text. It is more secure than PLAIN and LOGIN but less commonly used.

4. **DIGEST-MD5**: This is an extension of CRAM-MD5 and provides additional security features, such as mutual authentication and integrity protection. However, it is also less commonly used.

5. **NTLM**: This is a proprietary authentication protocol developed by Microsoft. It provides a more secure authentication mechanism than PLAIN or LOGIN and is often used in Windows environments.

6. **XOAUTH2**: This is an OAuth 2.0-based authentication method used for accessing email services like Gmail. It allows users to authenticate using tokens instead of passwords.

### Example Usage with `curl`:
When using `curl` to send an email via SMTP, you can specify the authentication method using the `--mail-auth` option or let `curl` negotiate the best method supported by the server.

For example:
```bash
curl --url "smtp://smtp.example.com" --ssl-reqd \
  --mail-from "sen...@example.com" \
  --mail-rcpt "reci...@example.com" \
  --user "username:password" \
  --upload-file email.txt
```

In this example:
- `--url` specifies the SMTP server URL.
- `--ssl-reqd` ensures the connection is secured with SSL/TLS.
- `--mail-from` specifies the sender's email address.
- `--mail-rcpt` specifies the recipient's email address.
- `--user` provides the username and password for authentication.
- `--upload-file` specifies the file containing the email content.

`curl` will automatically negotiate the best authentication method supported by the server based on the provided credentials.

### Note:
- Always use SMTP over TLS/SSL (`smtps://` or `--ssl-reqd`) to ensure that your credentials are transmitted securely.
- The availability of specific authentication methods depends on the SMTP server's configuration.


--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/fbe09664-c015-4414-a144-75f6e167fb7an%40googlegroups.com.

diego...@gmail.com

unread,
Mar 10, 2025, 4:14:09 PMMar 10
to Harbour Users

Ash

unread,
Mar 10, 2025, 5:04:27 PMMar 10
to Harbour Users
Gentlemen,

I now have some options, thank you both very much.

Regards,
Ash

Ash

unread,
Mar 11, 2025, 12:37:12 PMMar 11
to Harbour Users
Hello Gerald,

As i have a hotmail account, I tried the following at Windows 11 command prompt.

curl --url "smtp://smtp-mail.outlook.com" --ssl-reqd --mail-from "xx...@hotmail.com" --mail-rcpt "xx...@hotmail.com" --user "xx...@hotmail.com" --upload-file autoquit.log

After entering my password, I get the following output:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:06 --:--:--     0

curl: (67) Login denied

I checked my credentials and tried again - sadly the same results.

Regards,
Ash

Ash

unread,
Mar 11, 2025, 1:00:11 PMMar 11
to Harbour Users
curl 8.10.1 (Windows) libcurl/8.10.1 Schannel zlib/1.3 WinIDN
Release-Date: 2024-09-18

Regards,
Ash

Gerald Drouillard

unread,
Mar 11, 2025, 2:29:41 PMMar 11
to harbou...@googlegroups.com
Please check out one of the AI's in helping yourself find the solutions. 
For instance, deepseek.com response to "use curl to send email via outlook.com"

To send an email via Outlook.com using `curl`, you would typically need to use the Microsoft Graph API, which allows you to send emails programmatically. Below are the steps to achieve this:

### Prerequisites:
1. **Microsoft Azure Account**: You need to register an application in Azure to get the necessary credentials.
2. **API Permissions**: Ensure your application has the `Mail.Send` permission.
3. **Access Token**: You need to obtain an OAuth 2.0 access token to authenticate your requests.

### Steps:

1. **Register an Application in Azure**:
   - Go to the [Azure Portal](https://portal.azure.com/).
   - Navigate to "Azure Active Directory" > "App registrations" > "New registration".
   - Register your application and note down the `Client ID` and `Tenant ID`.

2. **Configure API Permissions**:
   - In your app registration, go to "API permissions" > "Add a permission" > "Microsoft Graph".
   - Select "Delegated permissions" and check `Mail.Send`.
   - Click "Grant admin consent" to grant the permissions.

3. **Obtain an Access Token**:
   - Use the OAuth 2.0 authorization code flow to obtain an access token. You can use the following `curl` command to get the token:

     ```bash
     curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \
     -d "client_id=YOUR_CLIENT_ID" \
     -d "scope=https://graph.microsoft.com/.default" \
     -d "client_secret=YOUR_CLIENT_SECRET" \
     -d "grant_type=client_credentials" \
     "https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token"
     ```

   - Replace `YOUR_CLIENT_ID`, `YOUR_CLIENT_SECRET`, and `YOUR_TENANT_ID` with your actual values.

4. **Send Email Using Microsoft Graph API**:
   - Once you have the access token, you can use it to send an email via the Microsoft Graph API. Here is an example `curl` command:

     ```bash
     curl -X POST https://graph.microsoft.com/v1.0/me/sendMail \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "message": {
         "subject": "Test Email",
         "body": {
           "contentType": "Text",
           "content": "This is a test email sent via Microsoft Graph API."
         },
         "toRecipients": [
           {
             "emailAddress": {
               "address": "reci...@example.com"
             }
           }
         ]
       }
     }'
     ```

   - Replace `YOUR_ACCESS_TOKEN` with the access token you obtained in the previous step, and `reci...@example.com` with the actual recipient's email address.

### Notes:
- The above example uses the `client_credentials` grant type, which is suitable for app-only scenarios. If you need to send emails on behalf of a user, you should use the `authorization_code` grant type and handle user consent.
- Ensure that the `Mail.Send` permission is correctly configured and that the access token has the necessary scopes.

### Example with Authorization Code Flow:
If you are using the authorization code flow, you would first need to redirect the user to the Microsoft login page to obtain an authorization code, then exchange that code for an access token.

```bash
# Step 1: Redirect user to login and get authorization code
# Step 2: Exchange authorization code for access token
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=YOUR_CLIENT_ID" \
-d "scope=https://graph.microsoft.com/.default" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "grant_type=authorization_code" \
-d "code=YOUR_AUTHORIZATION_CODE" \
-d "redirect_uri=YOUR_REDIRECT_URI" \
"https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token"
```

Replace `YOUR_AUTHORIZATION_CODE` and `YOUR_REDIRECT_URI` with the actual values.

### Conclusion:
Using `curl` to send an email via Outlook.com involves interacting with the Microsoft Graph API, obtaining an access token, and then making a POST request to the `sendMail` endpoint. Ensure you have the correct permissions and follow the OAuth 2.0 flow appropriate for your use case.

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

Ash

unread,
Mar 11, 2025, 5:43:14 PMMar 11
to Harbour Users
Hello Gerald,

You have provided a lot of information here to sift through and set up the new email environment. Many thanks.

Regards,
Ash

P.S. Deepseek - a golden nugget!
Reply all
Reply to author
Forward
0 new messages