Webmail via Preview button
I have a program where my clients may use either the default email client (Outlook) on their Windows machine, or they may use a WebMail client. Clicking the email icon in the preview pane of a report works fine if I'm using "PreviewInEmailClient=True", but I've tried many configutations to try to get WebMail to work using the Preview Email button. If I have my own button on a form, I can easily launch WebMail and attach reports, but I don't know how to accomplish this from within the Report Preview Pane when clicking the email icon. I get an AV when the ReportBeforeEmail routine exits.
My code looks like this:
procedure TfrmExport.ReportBeforeEmail(Sender: TObject);
begin
...
if EmailUseWebMail then
begin
Report.EmailSettings.ShowEmailDialog:=True;
Report.EmailSettings.PreviewInEmailClient:=False;
Report.EmailSettings.ConnectionSettings.MailService:='Outlook365';
Report.EmailSettings.ConnectionSettings.HostAddress:=EMailServer;
Report.EmailSettings.ConnectionSettings.Port:=EMailPort;
Report.EmailSettings.ConnectionSettings.UserName:=EmailAddress;
Report.EmailSettings.ConnectionSettings.Password:=EmailPassword;
Report.EmailSettings.ConnectionSettings.UseTLS:=True;
end
else
begin // using default email client like Outlook
Report.EmailSettings.ShowEmailDialog:=False;
Report.EmailSettings.PreviewInEmailClient:=True;
Report.EmailSettings.ConnectionSettings.MailService:='SMTP';
end;
...
end;
And a side question. If my "ConnectionSettings.MailService" isn't Outlook365 or GMail, then can I simply use either one of those designations, but change the HostAddress and Port to the correct settings, like for Hotmail/Live.com, Yahoo mail, etc.?
Thanks for any help.
My code looks like this:
procedure TfrmExport.ReportBeforeEmail(Sender: TObject);
begin
...
if EmailUseWebMail then
begin
Report.EmailSettings.ShowEmailDialog:=True;
Report.EmailSettings.PreviewInEmailClient:=False;
Report.EmailSettings.ConnectionSettings.MailService:='Outlook365';
Report.EmailSettings.ConnectionSettings.HostAddress:=EMailServer;
Report.EmailSettings.ConnectionSettings.Port:=EMailPort;
Report.EmailSettings.ConnectionSettings.UserName:=EmailAddress;
Report.EmailSettings.ConnectionSettings.Password:=EmailPassword;
Report.EmailSettings.ConnectionSettings.UseTLS:=True;
end
else
begin // using default email client like Outlook
Report.EmailSettings.ShowEmailDialog:=False;
Report.EmailSettings.PreviewInEmailClient:=True;
Report.EmailSettings.ConnectionSettings.MailService:='SMTP';
end;
...
end;
And a side question. If my "ConnectionSettings.MailService" isn't Outlook365 or GMail, then can I simply use either one of those designations, but change the HostAddress and Port to the correct settings, like for Hotmail/Live.com, Yahoo mail, etc.?
Thanks for any help.
Comments
I apologize for the late reply, I needed to finalize some articles for this response.
Web mail is a bit different from the standard SMTP email plugins that you're used to. .
- ReportBuilder had two types of email support. SMTP and Web. The SMTP email plugins all have a prefix of SMTP before the plugin name (i.e. ppSMTPOutlook, ppSMTPIndy10, etc.). The web mail plugins all have the RESTMail prefix. The SMTP plugins either directly connect to an email server or communicate with the email client installed on the machine. The RESTMail plugins communicate with Web Mail services such as Gmail via HTTP and require app registration.
- The best place to start for Web Mail setup is the following article:
http://rbwiki.digital-metaphors.com/output/email/web-mail-overview/
- Currently only web mail services that provide a public REST API are supported. Yahoo does not offer one. Hotmail/Live.com = Outlook 365 (Outlook.com).
- RB 21 introduced support for multiple email plugins at once. See the following article for more information and and example.
http://rbwiki.digital-metaphors.com/output/email/how-to-multiple-email-plugins/
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com