开发者

Outlook automation with Delphi - Queue

开发者 https://www.devze.com 2023-04-11 03:21 出处:网络
I currently have the following code: while not (sqlMailMergeData.Eof) do begin if sqlMailMergeData.FieldByName(\'Email\').AsString <> \'\' then

I currently have the following code:

  while not (sqlMailMergeData.Eof) do
  begin

  if sqlMailMergeData.FieldByName('Email').AsString <> '' then
  begin
  Inc(Count);
  {Connect to Outlook}
  MailItem := OpOutlook1.CreateMailItem;
  MailItem.MsgTo := sqlMailMergeData.FieldByName('Email').AsString;
  MailItem.Body := F开发者_C百科orm48.Memo1.Text;
  MailItem.Subject := Form48.Edit3.Text;
  MailItem.Send;
  end;

  Form34.sqlMailMergeData.next;
  end;

However Outlook prompts you to allow ever email with a delay of 5 seconds. Sending after the loop overwrite the same MailItem.

  MailItem.Save;

Saves all the items to draft without prompting. This is not a bad solution and could be an extra feature but requires more user input to move the items to outbox.

Is there a function to send each mail item to the outbox? or should I consider creating a string of all the email address e.g.

MailItem.MsgTo := "example@email.com; example2@email.com"

Thanks


When working with outlook, you might consider using outlook redemption1, this way you can bypass the security prompt and send the mail directly from your code.


Then your only option is to do what Redemption (I am its author) is doing under the hood - use Extended MAPI.


This is the code which works fine for me:

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

    // Repet the code below for each mail:
    OutlookMail := Outlook.CreateItem (olMailItem);  // olMailItem = 0;
    OutlookMail.Recipients.Add ('example@email.com').Resolve;
    OutlookMail.Recipients.Add ('example2@email.com').Resolve;
    OutlookMail.Subject := Form48.Edit3.Text;
    OutlookMail.Body := Form48.Memo1.Text;
    OutlookMail.BodyFormat := olFormatHTML;
    // OutlookMail.SendUsingAccount := OutlookAccount;  // If you need to select the acount
    OutlookMail.Send;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号