Avatar billede mysitesolution Nybegynder
30. marts 2003 - 01:56 Der er 6 kommentarer og
3 løsninger

Sen mail funktion

Heii... er der ikke en der vil lave en send mail funktion til mig:

SendMail(Modtager, Emne,Body, Afsender....

jeg har alle de nyeste indy komponenter
Avatar billede mysitesolution Nybegynder
30. marts 2003 - 01:57 #1
den skal også kunne sende uden en smtp adresse...istedet skal der bruges idsmtpserver
Avatar billede stone Forsker
30. marts 2003 - 08:52 #2
i delphi er der et godt eksempel på send/recieve mail:
kan du bruge den?
Example

To recreate this example, you will need to create a new blank Delphi application.

Place 6 TEdits, a TMemo, a TCheckBox, 2 TButtons, and a TNMPOP3 on the Form.

Component Descriptions:
Edit1: Host
Edit2: User ID
Edit3: Password
Edit4: Attachment Path
Edit5: From (Person that sent the E-Mail)
Edit6: Subject of the E-Mail
Memo1: Message Body
Button1: Connect/Disconnect
Button2: Get Mail Message
CheckBox1: Delete message after reading


Insert the following code into Button1's OnClick event:


procedure TForm1.Button1Click(Sender: TObject);
begin
  if NMPOP31.Connected then
    NMPOP31.Disconnect
  else
  begin
    NMPOP31.Host := Edit1.Text;
    NMPOP31.UserID := Edit2.Text;
    NMPOP31.Password := Edit3.Text;
    NMPOP31.DeleteOnRead := Checkbox1.Checked;
    NMPOP31.AttachFilePath := Edit4.Text;
    NMPOP31.Connect;
  end;
end;

When Button1 gets clicked, if there is a connection with the remote host, the Disconnect method is executed to close the connection. If there is no connection present, the Host property, which specifies the mail server to connect to, is set to the value in Edit1. The UserID property, which specifies the user name to log in as, is set to the vlaue in Edit2. The Password property, which should correspond with the UserID property, is set to the value in Edit3. If CheckBox1 is checked (true), then messages are deleted as they are retrieved by the GetMailMessage method, since the DeleteOnRead property is set to the value of CheckBox1.Checked. the AttachFilePath property is set to the value in Edit4, and the Connect method establishes a connection with the remote host.

Insert the following test into NMPOP31's OnConnect method:

procedure TForm1.NMPOP31Connect(Sender: TObject);
begin
  if NMPOP31.MailCount > 0 then
    ShowMessage(IntToStr(NMPOP31.MailCount)+' messages in your mailbox')
  else
    ShowMessage('No messages waiting');
end;

When the client connects to the mail host, the OnConnect event is called. If there are messages
waiting on the server, a message box pops up displaying the number stored in the MailCount property, stating how many messages are waiting on the server. If there are no messages, a box is displayed stating that there are no messages.

Insert the following code into Button2's OnClick event:

procedure TForm1.Button2Click(Sender: TObject);
var
  S: String;
  M: Integer;
begin
  if NMPOP31.MailCount > 0 then
  begin
    if InputQuery('Retrieve an E-Mail message', 'Which message? (1-'+IntToStr(NMPOP31.MailCount)+')', S) then
    begin
      M := StrToIntDef(S, -1);
      If (M < 0) or (M > NMPOP31.MailCount) then
        ShowMessage('Invalid message index')
      else
        NMPOP31.GetMailMessage(M);
    end;
  end
  else
    ShowMessage('No Messages to Get');
end;

When Button2 is clicked, if there are messages on the server (NMPOP31.MailCount > 0), the InputQuery function requests a message number to retrieve. If the OK button in clicked, the number typed in is checked for validity with the actual number of messages. If the specified mail number is invalid, a message box is displayed saying the message doesn't exist. If the specified message exists, it is retrieved using the GetMailMessage method.

Insert the following code into NMPOP31's OnRetrieveEnd event:

procedure TForm1.NMPOP31RetrieveEnd(Sender: TObject);
begin
  Memo1.Text := NMPOP31.MailMessage.Body.Text;
  Edit6.Text := NMPOP31.MailMessage.Subject;
  Edit5.Text := NMPOP31.MailMessage.From;
end;

The OnRetrieveEnd event is called when a message has completed being retrieved from the remote host. In this case, Memo1 is set to the Body of the MailMessage property, displaying the contents of the message.Edit6 is set to the Subject of the MailMessage property, displaying the subject line of the message. Edit5 is set to the sender of the message, stored in the From property of the MailMessage property

Insert the following code into NMPOP31's OnDecodeStart event:

procedure TForm1.NMPOP31DecodeStart(var FileName: String);
var
  S: String;
begin
  S := FileName;
  if InputQuery('Save File Attachment', 'Filename?', S) then
    FileName := S;
end;

When a file attachment begins decoding, the OnDecodeStart event is called. In this example, the InputQuery function is used to retrieve a file name. If the Ok button is clicked, the FileName parameter is changed to the new value entered in the input box.
Avatar billede dkklein Nybegynder
30. marts 2003 - 09:34 #3
Hvordan kan du sende uden en SMTP server adresse ?

Men ellers er der QuickSend:


Sends a message without an Indy message instance.


class procedure QuickSend(const AHost: String; const ASubject: String; const ATo: String; const AFrom: String; const AText: String);

Parameters

const AHost: String

SMTP server used to send the message.


const ASubject: String

Subject of the message.


const ATo: String

Recipient(s) of the message.


const AFrom: String

Person sending the message.


const AText: String

Body text for the message.


Description

QuickSend is a class procedure that allows the SMTP client to quickly send a message without the need for a TIdMessage instance. QuickSend cannot be used to send messages with attachments.
Parameters for the method are used to construct a TIdMessage instance, connect and send the message to the SMTP server, and to Disconnect from the SMTP server. The following is an example of using QuickSend with pre-defined application variables:

  try
    ASmtp.QuickSend(SMailhost, SSubject, SUserAccount,
      SContactAccount, ABody.Text);
  except on E:
    do DoReminderTransmitError(E);
  end;
Avatar billede mysitesolution Nybegynder
30. marts 2003 - 11:34 #4
hmm... hvad skal man tilføje i uses for at bruge quicksend
Avatar billede ziron Nybegynder
30. marts 2003 - 17:12 #5
hmm længe siden denne er lavet, men kig lige på det...

Procedure SendMail(Modtager, Afsender, Emne, Text, SmtpMailServer, SmtpUser, SmtpPass : String; SmtpPort, SmtpLogin : Integer);
var
  SMTP : TIdSMTP;
  IdMsgSend: TIdMessage;
begin
  SMTP := TIdSMTP.Create(NIL);
  IdMsgSend := TIdMessage.Create(NIL);

  IdMsgSend.CharSet := 'US-ASCII';

  with IdMsgSend do
  begin

    Body.Text := Text;
    From.Text := Afsender;
    Recipients.EMailAddresses := Modtager; { To: header }
    Subject := Emne; { Subject: header }

//Her skal laves noget med priority...

    Priority := TIdMessagePriority(mpNormal); { Message Priority }
  end;

  if SmtpLogin = 1 then
    begin
      {authentication settings}
      SMTP.AuthenticationType := atLogin;
    end
  else
    begin
    SMTP.AuthenticationType := atNone;
  end;

  SMTP.MailAgent := 'Test mailsender';

  //User settings
  SMTP.UserID := SmtpUser; //brugernavn på serveren.
  SMTP.Password := SmtpPass; //password på serevren.

  {General setup}
  SMTP.Host := SmtpMailServer; //ip til serveren.
  SMTP.Port := SmtpPort; //Server port.

  {now we send the message}
  SMTP.Connect;
  try
    SMTP.Send(IdMsgSend);
  finally
    SMTP.Disconnect;
  end;

  SMTP.Free;
  ShowMessage('Din Besked blev sendt');
end;

/ZIRON
Avatar billede mysitesolution Nybegynder
30. marts 2003 - 17:44 #6
virker næsten fint, men den sender body/teksten somen vedhæftet .dat fil
Avatar billede ziron Nybegynder
30. marts 2003 - 17:55 #7
hmm prøv lige at send en mail til test@kulhytten.dk ...
Avatar billede mysitesolution Nybegynder
30. marts 2003 - 18:00 #8
sendt
Avatar billede ziron Nybegynder
30. marts 2003 - 18:31 #9
ja okay det kan jeg godt se, men har ikke lige tid til at kigge på det nu. prøv at se i dokumentationen for indy-tingen...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester