Delphi中的电子邮件程序

5
我正在使用Delphi 7构建一款邮件发送应用程序。我的电脑上默认的电子邮件客户端是Lotus Notes。我在应用程序中尝试了ShellExecute命令,但是这样会弹出Lotus Notes并要求用户填写主题、正文等信息,然后再点击Lotus Notes中的发送按钮。
我希望当用户点击我的应用程序中的发送按钮时,可以自动使用Lotus Notes发送电子邮件。我们能否使用ShellExecute实现这一点?我也尝试过使用Indy组件,但是我没有获得SMTP详细信息。我该如何找到SMTP服务器的详细信息?
谢谢您的帮助。

1
在2011年还在使用Lotus Notes吗?继续忍受,比我们其他人放弃得更久。 - Warren P
3个回答

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;

非常感谢你,Michael。提供的解决方案没有出现任何错误。我只是做了一个更改,我已经注释掉了Session.Initialize;非常感谢。很棒的解决方案。 - Nalu

2
如果您使用Indy,邮件将不会通过Lotus Notes发送,而是直接从应用程序发送到指定的邮件服务器。
如果您有邮件服务器或电子邮件帐户,可以使用Indy中的IdSmtp组件,并将其配置为您的邮件服务器主机名、端口名和身份验证方法。如果您不知道如何获取此类信息,可以联系您的邮件服务公司,并询问他们的配置。
另一种发送电子邮件的方法是使用IdSmtpServer组件创建SMTP邮件服务器。这样,您的应用程序就不需要外部邮件服务器。
请注意,在两种情况下,电子邮件都是通过您指定的电子邮件地址发送的,并且目标计算机上安装的默认电子邮件客户端不会被使用。

有关如何创建SMTP电子邮件服务器的任何想法吗? - Nalu
您可以从以下网址了解如何使用Indy 10构建SMTP服务器:http://www.devarticles.com/c/a/Delphi-Kylix/Creating-an-SMTP-Server/ - vcldeveloper
Lotus Domino 内置了 MTA。 - Premature Optimization

1

Jedi Code Library(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的情况下正常工作。


我在哪里可以获取有关MAPI组件的帮助? - Nalu
这些功能能否在HTML主体中实现? - Whiler
@Whiler:“MAPI不适用于HTML消息” - http://support.microsoft.com/kb/268440/zh-cn - mjn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接