德尔福的电子邮件程序

时间:2011-09-26 11:54:22

标签: delphi

我正在delphi 7中构建电子邮件发送应用程序。我机器上的默认电子邮件客户端配置了Lotus Notes。 我在应用程序中单击“发送”按钮时尝试了shellExecute命令。但是在这个ShellExecute中弹出莲花笔记给用户注意主题,身体等,然后用户需要点击莲花笔记中的发送按钮。

我希望当用户点击我的应用程序的“发送”按钮时,应该使用莲花笔记自动发送电子邮件。我们可以使用ShellExecute吗?我也试过使用Indy组件,但我没有得到SMTP详细信息。如何找到SMTP服务器详细信息? 谢谢你的帮助

3 个答案:

答案 0 :(得分:3)

为了使用Lotus Notes发送电子邮件(即使它看起来像一个过度杀戮)我发现this post并尝试将其翻译成Delphi代码,但我无法在任何地方进行测试,所以我无法告诉你这是否有效。我已将原始评论留在那里。

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;

答案 1 :(得分:2)

如果您使用Indy,则电子邮件不会通过Lotus Notes发送,而是直接从您的应用程序发送到指定的邮件服务器。

如果您有邮件服务器或拥有电子邮件帐户,则可以使用Indy中的IdSmtp组件,并使用您的邮件服务器主机名,端口名和身份验证方法对其进行配置。如果您不知道如何获取此类信息,可以联系您的邮件服务公司,并询问他们的配置。

发送电子邮件的另一种方法是使用IdSmtpServer组件自行创建SMTP邮件服务器。这样您的应用就不需要外部邮件服务器了。

请注意,在这两种情况下,电子邮件都是通过您指定的电子邮件地址发送的,并且未使用目标计算机上安装的默认电子邮件客户端。

答案 2 :(得分:1)

Jedi代码库(JCL)包含一个MAPI帮助程序类“TJclEmail”(在单元source \ windows \ JclMapi中),具有易于使用的命令,发送邮件和传真,有或没有显示撰写邮件窗口。

示例:

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

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

是方便的方法,在内部使用类。

如果Lotus Notes已注册为MAPI邮件处理程序,则它应该在没有SMTP / Indy的情况下工作。