Options

Error in document sending thrugh Email

kmkaotkmkaot Member Posts: 261
Dear friends,

I am not getting results for sending a documents as attachment in email.

can you help please...


SMTPsetup.GET;
SenderName:=SMTPsetup."Email sender Name";
SenderAddress:=SMTPsetup."Email sender email";
Recipients:=vendorRec."E-Mail"+';'+SMTPsetup."Manager Email";

kSubject:="No."+' PO for '+FORMAT(Amount);
kBody:=' ';
Tofile := Name;
Tofile := "No."+'.pdf';


FileAndPathName := SMTPsetup."Path to Save Report" + Tofile;

FileAndPathName:=CONVERTSTR(FileAndPathName,'\','/');

FileName:=FileAndPathName;
WHILE STRPOS(FileName,'\') > 0 DO
FileName := COPYSTR(FileName, STRPOS(FileName,'\') +1);

CurrPage.SETSELECTIONFILTER(Rec);
REPORT.SAVEASPDF(405, FileName, Rec);

CLEAR(email);
email.CreateMessage(Recipients,'','',kSubject,kBody,FALSE,FALSE);
email.AddBodyline(' Dear Sir/Madam');
email.AddBodyline('<BR><BR>');
email.AddBodyline(' PO Document '+"No."+' '+"Pay-to Name"+' approved ');
email.AddBodyline('<BR><BR>');
email.AddBodyline('Operations');
email.AddBodyline('<BR><BR>');
email.AddBodyline('My Company');
email.AttachFile(FileName);
MESSAGE(FileName);
email.Send;
Pleasee..

kris

Answers

  • Options
    zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    You did not get the VendorRec.

    You have to do like

    CLEAR(VendorRec);
    VendorRec.SETCURRENTKEY("No.");
    VendorRec.GET('some vendor');
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
  • Options
    kmkaotkmkaot Member Posts: 261
    This code is already there. I did not show all.
    Do we require MS outlook on Server

    Warm regards
    Krish
  • Options
    vaprogvaprog Member Posts: 1,118
    kmkaot wrote: »
    Do we require MS outlook on Server
    No, on the client.

    What do you do with the path? why do you first prepend it, then chop it off again before you use it?

    Without a path, I do not know if SAVEASPDF and email.AttachFile assume the same path. better specify the path. Make sure that SMTPsetup."Path to Save Report" ends with a (back)slash.

    Where did you look for results? Look in your outbox and in sent items.
    Changing the ShowNewMailDialog parameter to true in email.CreateMessage while developping might also help to verify everything.
  • Options
    rehansattirehansatti Member Posts: 36
    Hi Kamkaot,
    Which version of NAV are you using? I have developed a custom functionality of sending Email in batch for posted documents. I used the system generated path as follows. May be this could help you.
    SendReport()
    {
    ServerAttachmentFilePath := GenerateReport(HeaderDoc,ReportID,CustomReportSelection);
    SendAttachment(SalesDocumentNo,Customer."No.",ServerAttachmentFilePath,DocumentType,SendTo,CustomReportSelection);
    }

    GenerateReport()
    {
    IF CustomReportLayout.GET(CustomReportSelection."Custom Report Layout ID") THEN BEGIN
    ReportLayoutSelection.SetTempLayoutSelected(CustomReportLayout.ID);
    REPORT.RUNMODAL(CustomReportSelection."Report ID",NOT HideDialog,FALSE,HeaderDoc);
    ReportLayoutSelection.SetTempLayoutSelected(0);
    END ELSE
    IF NOT REPORT.SAVEASPDF(ReportID,ServerAttachmentFilePath,HeaderDoc) THEN
    ERROR(ServerSaveAsPdfFailedErr);

    }
    Best Regards
    Rehan Satti
    Microsoft Dynamics NAV Technical Consultant
    Please verify the answer if it satisfy your question. This will help other members of community.
  • Options
    kmkaotkmkaot Member Posts: 261
    Thank you all.
    I got the solution.

    The file which was stored in server was not allowed to send from client system. we need to copy the same to client system first.

    I have used file Managment CU to get the file

    Thank you and warm regards
    Kris
  • Options
    zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    You are welcome :)
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
Sign In or Register to comment.