web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Avoid to send email to contacts with same e-mail

(0) ShareShare
ReportReport
Posted on by 273

Hi all,

Imagine this possible situation

I have contact A with e-mail X, and contact B with same e-mail X.
I'm making a a function to go though all contacts and send an email, but in this case i don't wan't that contact B receive another e-mail.

Contact.RESET;
Contact.SETRANGE("No.","No.");
Contact.SETFILTER(Contact."E-Mail",'<>%1','');

IF Contact.FINDSET THEN REPEAT 
  Recipients:=Contact."E-Mail";




//Recipients:='roliveira@sameca.com';//
SMTPMailSetup.GET;
SMTPMail.CreateMessage(
  '',
  'roliveira@sameca.com',
  Recipients,
  TestMailTitleTxt1,
  STRSUBSTNO(
    MailBody,
    USERID),TRUE);
SMTPMail.Send;

UNTIL Contact.NEXT=0;


Im thinking of using a temp table and whenever an e-mail is sent the address will be inserted in that table and then check before send the e-mail if it already exists in the table.

Would like to read some opinions. Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at

    Hello!

    I would create a temporary table with only text field (because I can't remember any existing table with key field of text or long code type).

    After that i would use next conctruction:

    Contact.RESET;
    Contact.SETRANGE("No.","No.");
    Contact.SETFILTER(Contact."E-Mail",'<>%1','');
    
    IF Contact.FINDSET THEN REPEAT 

    temprecord.init;

    temprecord.keyfield := Contact."E-mail";

    if temprecord.INSERT THEN BEGIN

    SMTPMailSetup.GET;

    SMTPMail.CreateMessage( '', 'roliveira@sameca.com', Contact."E-mail", TestMailTitleTxt1, STRSUBSTNO( MailBody, USERID),TRUE);

    SMTPMail.Send;

    END;

    UNTIL Contact.next = 0;

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Yes you can do that, after sending the email store the contact in the temporary contact table, you don't need to create another table for this purpose and before sending the email just check in the temporary table if there is a record with that email, if not send the email and insert the record.

  • Verified answer
    Olister Rumao Profile Picture
    3,967 on at

    Hi Rikarddo,

    All you need to do is sort the Contact By Email.

    Store the Currently used Contact Email in a variable and then check if the variable value is not equal to the next contact record.

    In the following code I've created a variable called as tempemail of the type Text and use the code

    TempEmail := '';

    Contact.RESET;

    Contact.SETRANGE("No.","No.");

    Contact.SETFILTER(Contact."E-mail",'<>%1','');

    Contact.SETCURRENTKEY(Contact."E-mail");

    Contact.ASCENDING(TRUE); //Sort by E-mail

    IF Contact.FINDSET THEN

    REPEAT

     IF TempEmail <> Contact."E-mail" THEN BEGIN

     //Your Emailing Code

      Recipients:=Contact."E-Mail";

      SMTPMailSetup.GET;

      SMTPMail.CreateMessage('','roliveira@sameca.com',Recipients,TestMailTitleTxt1,

       STRSUBSTNO(MailBody,USERID),TRUE);

     SMTPMail.Send;

     TempEmail := Recipients;

     END;

    UNTIL Contact.NEXT=0;

  • Rikarddo Profile Picture
    273 on at

    Thanks for the help! All the answers are great and now i have the "know how" to finish it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans