Topic: send mail

hello friends..
i need send mail working sample...
please upload...

Re: send mail

http://myvisualdatabase.com/forum/viewtopic.php?id=3917

Re: send mail

An example:

The code below tries to open Outlook and fill it with HTML content, if that fails a simple text based email is sent.


procedure frmEmail_btnSendEmail_OnClick (Sender: TObject; var Cancel: boolean);
const
    olMAILITEM = 0;
var
    Outlook: Variant;
    vMailItem: variant;
    indx : integer;
    txt, propName: String;
    sList:TstringList;
begin
         sList:=TStringList.Create;
         sList.Add('<html>');
         sList.Add('<head>');
         sList.add('<style>');
         sList.Add('table, th, td {');
         sList.Add(' border: 1px solid #dddddd; text-align: left; padding: 8px');
         sList.Add('}');
         sList.Add('</style>');
         sList.add('</head>');
         sList.Add('<body>');
         sList.Add('<table>');
         sList.Add('<tr><th>Part Number</th>'+ '<th>BSuite#</th>' + '<th>Description'+ '</th>'+'<th>Qty'+'</th>'+'<th>For'+'</th>'+'</tr>');

         for indx := 0 to frmEmail.tgEmailList.RowCount-1 do
         begin
            sList.Add('<tr><td>'+frmEmail.tgEmailList.Cells[0,indx] + '</td>' + '<td>' +frmEmail.tgEmailList.Cells[1,indx] +'</td>'+'<td>'+frmEmail.tgEmailList.Cells[2,indx]+'</td>'+'<td> x '+frmEmail.tgEmailList.Cells[3,indx]+'</td>'+'<td>'+frmEmail.tgEmailList.Cells[4,indx]+'</td></tr>');
         end;
         sList.Add('</table>');
         sList.Add('</body>');
         sList.Add('</html>');


        if frmEmail.cmbSupplierList.ItemIndex = -1 then
         messagebox('You have not selected an order to email. Please select a supplier', 'EMAILING ERROR',0)
       else
       begin
          frmEmail.tgEmailList.dbPopUPMenu.Items.Find('Copy All').click;
          txt := ClipboardGet;
         try
           propName := 'https://schemas.microsoft.com/mapi/proptag/0x59020003';
           Outlook := CreateOleObject('Outlook.Application');
           vMailItem := Outlook.GetNamespace('MAPI');
           vMailItem.Logon(null,null,true,null);
           vMailItem := Outlook.CreateItem(olMailItem);
           vMailItem.Recipients.Add(frmEmail.cmbEmailAddress.Text);
           vMailItem.Subject := frmEmail.cmbSupplierList.Text;
           vMailItem.HTMLBody := sList.text;
           OutLook.SetProperty(propName, EncodingFlag);
           vMailItem.Send;
           Outlook.free;
         except

           openURL('mailto:'+frmEmail.cmbEmailAddress.Text+'?Subject='+frmEmail.cmbSupplierList.Text+' Order'+'&Body='+sList.text);
         end;
       end;

    frmEmail.tgEmailList.SelectRange(0,frmEmail.tgEmailList.RowCount -1,TRUE);
    for indx := 0 to frmEmail.tgEmailList.RowCount -1 do
    begin

      SQLExecute('UPDATE orders SET orderEmailed = 1 WHERE orders.id = "'+ intToStr(frmEmail.tgEmailList.dbIndexToID(indx))+'"');

    end;
    frmEmail.cmbSupplierList.ItemIndex := -1;
    sList.free;
end;
On a clear disk you can seek forever

Re: send mail

Thanks both of you ..

I'll try both procedures

Re: send mail

hello CDB . Can You post Sample project.

Re: send mail

Sample project attached.

Change all the 'fake email addresses ' with real ones in the script.  Of course in a real environment you may use a textbox.text for the email address or a combobox.

Post's attachments

Attachment icon email test.zip 14.13 kb, 303 downloads since 2021-09-11 

On a clear disk you can seek forever

Re: send mail

Hi

The email test.zip file does not contain any code! Have you found a solution to send emails under windows 10? Can someone post a project that works?

Thank you
George

8 (edited by CDB 2022-12-01 10:13:55)

Re: send mail

geochrist wrote:

Hi

The email test.zip file does not contain any code!


I'm not sure what you mean that no code is in the zip file.



Below is code that works in Windows 10. I developed it on a Windows 10 PC.  Note Outlook can be temperamental  when using HTML, it may not always display correctly.

This takes information from a tablegrid and attempts to format it as a grid in an Outlook email. The text in red is all that is needed to actually use Outlook.  The MAILTO  line will work in any modern email client


procedure frmEmail_btnSendEmail_OnClick (Sender: TObject; var Cancel: boolean);
const
    olMAILITEM = 0;
var
    Outlook: Variant;
    vMailItem: variant;
    indx : integer;
    txt, propName: String;
    sList:TstringList;
begin
         sList:=TStringList.Create;
         sList.Add('<html>');
         sList.Add('<head>');
         sList.add('<style>');
         sList.Add('table, th, td {');
         sList.Add(' border: 1px solid #dddddd; text-align: left; padding: 8px');
         sList.Add('}');
         sList.Add('</style>');
         sList.add('</head>');
         sList.Add('<body>');
         sList.Add('<table>');
         sList.Add('<tr><th>Part Number</th>'+ '<th>BSuite#</th>' + '<th>Description'+ '</th>'+'<th>Qty'+'</th>'+'<th>For'+'</th>'+'</tr>');

         for indx := 0 to frmEmail.tgEmailList.RowCount-1 do
         begin
            sList.Add('<tr><td>'+frmEmail.tgEmailList.Cells[0,indx] + '</td>' + '<td>' +frmEmail.tgEmailList.Cells[1,indx] +'</td>'+'<td>'+frmEmail.tgEmailList.Cells[2,indx]+'</td>'+'<td> x '+frmEmail.tgEmailList.Cells[3,indx]+'</td>'+'<td>'+frmEmail.tgEmailList.Cells[4,indx]+'</td></tr>');
         end;
         sList.Add('</table>');
         sList.Add('</body>');
         sList.Add('</html>');


        if frmEmail.cmbSupplierList.ItemIndex = -1 then
         messagebox('You have not selected an order to email. Please select a supplier', 'EMAILING ERROR',0)
       else
       begin
          frmEmail.tgEmailList.dbPopUPMenu.Items.Find('Copy All').click;
          txt := ClipboardGet;
         try
         [color=red]  [b]propName := 'https://schemas.microsoft.com/mapi/proptag/0x59020003';
           Outlook := CreateOleObject('Outlook.Application');
           vMailItem := Outlook.GetNamespace('MAPI');
           vMailItem.Logon(null,null,true,null);
           vMailItem := Outlook.CreateItem(olMailItem);
           vMailItem.Recipients.Add(frmEmail.cmbEmailAddress.Text);
           vMailItem.Subject := frmEmail.cmbSupplierList.Text;
           vMailItem.HTMLBody := sList.text;
           OutLook.SetProperty(propName, EncodingFlag);
           vMailItem.Send;
           Outlook.free;[/b][/color]
         except

           openURL('mailto:'+frmEmail.cmbEmailAddress.Text+'?Subject='+frmEmail.cmbSupplierList.Text+' Order'+'&Body='+sList.text);
         end;
       end;

   
end;

   
On a clear disk you can seek forever

9 (edited by CDB 2022-12-01 10:12:11)

Re: send mail

Another option, but not easy to use on a system using MS Exchange is a simple

SendMail('YOUR SERVER NAME','YOUR EMAIL ADDRESS','YOUR EMAIL PASSWORD',PORT # Outlook is on,'RECIPIENT EMAIL ADDRESS','MESSAGE TITLE','MESSAGE TEXT');

A variation on the code in the previous post is below. This is aimed at sending an email on a corporate Outlook server system:


 Outlook := CreateOleObject('Outlook.Application');



    //vMailItem := Outlook.GetNamespace('MAPI');

    vMailItem.Logon;
    vMailItem := Outlook.CreateItem(olMailItem);
    vMailItem.Recipients.Add('RECIPIENT EMAIL ADDRESS HERE');
    vMailItem.Subject := 'What a wonderful test email';
    vMailItem.HTMLBody := sList.text; //   'This is a test --> how amazing';
    //vMailItem.Send;
    vMailItem.Display;
    Outlook.free;
On a clear disk you can seek forever