Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email Program in Delphi

Tags:

delphi

I am building an Email send application in delphi 7. Default email client on my machine is configured with lotus notes. I have tried shellExecute command on 'send' button click in application. But in this ShellExecute pop up the lotus notes to user with subject, body etc and then user needs to click on Send button in lotus notes.

I want when user click on Send button of my application then automatically email should be sent using lotus notes. Can we do this using ShellExecute? I tried using Indy components also but I didn't get the SMTP details. How can I find out SMTP server details? thanks for help

like image 717
Nalu Avatar asked Sep 26 '11 11:09

Nalu


3 Answers

For sending e-mails using Lotus Notes (even if it looks for me like an overkill a bit) I found this post and tried to translate it to Delphi code but I can't test it anywhere, so I can't tell you if this works or not. I have left the original comments in there.

uses
  ComObj, StrUtils;

// Public Sub SendNotesMail(Subject as string, attachment as string,
// recipient as string, bodytext as string,saveit as Boolean)
// This public sub will send a mail and attachment if neccessary to the
// recipient including the body text.
// Requires that notes client is installed on the system.

procedure SendNotesMail(const Subject: string; const Attachment: string;
  const Recipient: string; const BodyText: string; const SaveIt: Boolean);
var
  Maildb: OleVariant;     // The mail database
  UserName: string;       // The current users notes name
  MailDbName: string;     // The current users notes mail database name
  MailDoc: OleVariant;    // The mail document itself
  AttachME: OleVariant;   // The attachment richtextfile object
  Session: OleVariant;    // The notes session
  EmbedObj: OleVariant;   // The embedded object (Attachment)
begin
  Session := CreateOleObject('Notes.NotesSession');

  // Next line only works with 5.x and above. Replace password with your password
  Session.Initialize('password');

  // Get the sessions username and then calculate the mail file name
  // You may or may not need this as for MailDBname with some systems you
  // can pass an empty string or using above password you can use other mailboxes.
  UserName := Session.UserName;
  MailDbName := LeftStr(UserName, 1) + RightStr(UserName, (Length(UserName) - Pos(UserName, ' '))) + '.nsf';

  // Open the mail database in notes
  Maildb := Session.GETDATABASE('', MailDbName);
  if not Maildb.ISOPEN then
    Maildb.OPENMAIL;

  // Set up the new mail document
  MailDoc := Maildb.CREATEDOCUMENT;
  MailDoc.Form := 'Memo';
  MailDoc.sendto := Recipient;
  MailDoc.Subject := Subject;
  MailDoc.Body := BodyText;
  MailDoc.SAVEMESSAGEONSEND := SaveIt;

  // Set up the embedded object and attachment and attach it
  if Attachment <> '' Then
  begin
    AttachME := MailDoc.CREATERICHTEXTITEM('Attachment');
    EmbedObj := AttachME.EMBEDOBJECT(1454, '', Attachment, 'Attachment');
    MailDoc.CREATERICHTEXTITEM('Attachment');
  end;

  // Send the document
  MailDoc.PostedDate := Now; // Gets the mail to appear in the sent items folder
  MailDoc.SEND(0, Recipient);
end;
like image 72
TLama Avatar answered Nov 16 '22 08:11

TLama


If you use Indy, the email won't be sent through Lotus Notes, instead it will be sent directly from your application to the specified mail server.

If you have a mail server or have an email account, you can use IdSmtp component from Indy, and configure it with your mail server host name, port name, and authentication method. If you do not know how to obtain such info, you can contact your mail service company, and ask them about their configuration.

Another way to send an email is by creating a SMTP mail server yourself, using IdSmtpServer component. This way your app does not need an external mail server.

Take note that in both cases the email is sent via an email address that you specified, and the default email client installed on the target machine is not used.

like image 45
vcldeveloper Avatar answered Nov 16 '22 10:11

vcldeveloper


The Jedi Code Library (JCL) includes a MAPI helper class "TJclEmail" (in unit source\windows\JclMapi) with easy to use commands, sending mails and faxes with and without showing the compose mail window.

Example:

function JclSimpleBringUpSendMailDialog(const Subject, Body: AnsiString;
  const Attachment: TFileName = ''; ParentWND: THandle = 0;
  const ProfileName: AnsiString = ''; const Password: AnsiString = ''): Boolean;

and

function JclSimpleSendMail(const Recipient, Name, Subject, Body: AnsiString;
  const Attachment: TFileName = ''; ShowDialog: Boolean = True; ParentWND: THandle = 0;
  const ProfileName: AnsiString = ''; const Password: AnsiString = ''): Boolean;

are convenience methods, using the classes internally.

If Lotus notes is registered as the MAPI mail handler, it should work without SMTP /Indy.

like image 1
mjn Avatar answered Nov 16 '22 08:11

mjn