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, 120 downloads since 2021-09-11 

On a clear disk you can seek forever