send an email using the Outlook object

send an email using the Outlook object

Postby Otto » Mon May 13, 2024 5:07 pm

Hello friends,

I am trying to send an email using the Outlook object. I want the images to be embedded. ChatGPT suggests using:
oAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "image003").
But here, I receive a link error.

Lines 68, Functions/Procedures 2, pCodes 136
Embarcadero C++ 7.00 for Win32 Copyright (c) 1993-2015 Embarcadero Technologies, Inc.
C:\FWH\samples\msendok.c:
Error E2209 C:\FWH\samples\msendok.c 20: Unable to open include file 'OATTACHMENT.xns'
Error E2141 C:\FWH\samples\msendok.c 21: Declaration syntax error
Error E2451 C:\FWH\samples\msendok.c 53: Undefined symbol 'OATTACHMENT'
Error E2141 C:\FWH\samples\msendok.c 53: Declaration syntax error
Error E2190 C:\FWH\samples\msendok.c 53: Unexpected }
Error E2040 C:\FWH\samples\msendok.c 53: Declaration terminated incorrectly
Error E2190 C:\FWH\samples\msendok.c 61: Unexpected }


My question:
Does anyone have experience with sending emails with embedded images, or are there updates for the Outlook object?


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6334
Joined: Fri Oct 07, 2005 7:07 pm

Re: send an email using the Outlook object

Postby Otto » Mon May 13, 2024 6:54 pm

Hello friends,

I think it will be difficult with the Outlook object, as it becomes complex right away.
I have now checked a few more options and it seems - and it also worked immediately - that it is easiest to use a PHP script (PHPMailer) and call it with "run a PHP script from the command line" or shellexec.

Best regards,
Otto


command line
c:\www\php\php.exe emailsend.php

Code: Select all  Expand view  RUN


<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'c:/www/htdocs/PHPMailer/src/Exception.php';
require 'c:/www/htdocs/PHPMailer/src/PHPMailer.php';
require 'c:/www/htdocs/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true); // Passing `true` enables exceptions



try {
    // Server settings
    $mail->SMTPDebug = 2;                                   // Enable verbose debug output
    $mail->isSMTP();                                        // Set mailer to use SMTP
   // $mail->Host = 'smtp.gmail.com';                          // Specify main and backup SMTP servers    
    $mail->Host = 'smtp.xxxx.com';
    $mail->SMTPAuth = true;                                  // Enable SMTP authentication
    $mail->Username = 'otxxxxxx.com';                // SMTP username
    $mail->Password = '#oaxxxxxx!';                          // SMTP password
    $mail->SMTPSecure = 'tls';                              // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    // Recipients
    $mail->setFrom('ottxxxx.com', 'Mailer');
    $mail->addAddress('winhoxxxxxel.at', 'Joe User');     // Add a recipient

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b> and here is the image: <img src="cid:unique_cid">';

    // Attachments
   $mail->addEmbeddedImage('c:\www\hxxxxxxxataphotos\room-307.jpg', 'unique_cid', 'image_name.jpg'); // Path to your image, CID, and optional name

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>




 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6334
Joined: Fri Oct 07, 2005 7:07 pm

Re: send an email using the Outlook object

Postby TimStone » Tue May 14, 2024 2:46 am

Otto,

One big complication is that Microsoft is constantly changing Outlook, some features go away, some are being "rebuilt", and it is difficult. I have used Outlook since the old DOS days, and today's version is not nearly as reliable as what we had in the early days of Windows.

It might be best to utilize an alternate way of creating, sending, and tracking your emails instead of Outlook. I think that will become an ever more difficult interface.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: send an email using the Outlook object

Postby Otto » Tue May 14, 2024 7:46 am

Hello Tim,

Yes, you are right.

Another problem is that to have the Outlook object on a PC, you need a full Outlook installation. I googled for alternatives and found suggestions to use Python or PHP. As I have never used Python before, but I think one should get used to it a little, I decided to go with PHP.

There are also many ready-made samples available.

I will do as you suggested: create an HTML file, replace the placeholders within it, and then send the HTML using PHP. In practice, it is more or less the same code as with Outlook.

However, for my purpose, it is important that the pictures arrive at the recipient's address opened.

Best regards,
Otto


Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6334
Joined: Fri Oct 07, 2005 7:07 pm

Re: send an email using the Outlook object

Postby Silvio.Falconi » Tue May 14, 2024 7:50 am

Otto wrote:Hello Tim,

Yes, you are right.

Another problem is that to have the Outlook object on a PC, you need a full Outlook installation. I googled for alternatives and found suggestions to use Python or PHP. As I have never used Python before, but I think one should get used to it a little, I decided to go with PHP.

There are also many ready-made samples available.

I will do as you suggested: create an HTML file, replace the placeholders within it, and then send the HTML using PHP. In practice, it is more or less the same code as with Outlook.

However, for my purpose, it is important that the pictures arrive at the recipient's address opened.

Best regards,
Otto


Image




Otto,
with php

<?php
$message = "Line 1\r\nLine 2\r\nLine 3";
$message = wordwrap($message, 70, "\r\n");
mail('silvio.falconi@gmail.com', 'My Subject', $message);
?>


or with phpmailer

<form action="submit.php" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Your Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="subject">Subject:</label><br>
<input type="text" id="subject" name="subject" required><br><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4" cols="50" required></textarea><br><br>
<input type="submit" value="Submit" name="send">
</form>


<?php


use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;


require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';





if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["send"])) {

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$mail = new PHPMailer(true);

try {


$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'RECEIVER@gmail.com';
$mail->Password = 'SECRET';
$mail->SMTPSecure = "ssl";

$mail->Port = 465;

//Recipients
//Recipients
$mail->setFrom($email, $name);

$mail->addAddress("RECEIVER@gmail.com", );



//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $_POST["subject"];
$mail->Body = "Name: $name\nEmail: $email\n\nMessage:\n$message";
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo "Send Successfully!";

} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

}
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7066
Joined: Thu Oct 18, 2012 7:17 pm

Re: send an email using the Outlook object

Postby Otto » Tue May 14, 2024 10:08 am

Silvio, thank you.

How to insert images here: $mail->Body = "Name: $name\nEmail: $email\n\nMessage:\n$message"; ?

Regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6334
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 43 guests