Recent

Author Topic: Emailing through outlook!  (Read 4517 times)

vks

  • New Member
  • *
  • Posts: 33
Emailing through outlook!
« on: March 05, 2015, 06:57:13 am »
Hello..

I m here with another problem! :P
I have a code here to send mail from delphi through outlook.It is working fine.

Code: [Select]
uses
  ComObj;

procedure TForm1.Button16Click(Sender: TObject);
const
  olMailItem = 0;
  olByValue = 1;
var
  OutlookApp, MailItem : OLEVariant;
begin
  try
    OutlookApp := GetActiveOleObject('Outlook.Application');
  except
    OutlookApp := CreateOleObject('Outlook.Application');
  end;
  try
    MailItem := OutlookApp.CreateItem(olMailItem);
    MailItem.Recipients.Add('YourMailAddress@something.com');
    MailItem.Subject := 'Your Subject';
    MailItem.Body    := 'Your Message';
    MailItem.Send;
  finally
    myAttachments := VarNull;
    OutlookApp    := VarNull;
  end;
end;



But when i try to assign MailItem.Body to a string variable,like:

Code: [Select]
var
s: String;

procedure TForm1.Button16Click(Sender: TObject);
...
s:='Hello';
...
MailItem.Body:=s;


This code converts the string to other language when I see it in inbox.
I am unable to know what the problem is.Kindly do help me with it.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Emailing through outlook!
« Reply #1 on: March 05, 2015, 01:10:42 pm »
MailItem.Body:= UTF8Decode(s);  ?

vks

  • New Member
  • *
  • Posts: 33
Re: Emailing through outlook!
« Reply #2 on: March 05, 2015, 01:39:13 pm »
Hello ChrisF..

I got 'SIGSEGV exception' :-(

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Emailing through outlook!
« Reply #3 on: March 05, 2015, 02:51:33 pm »
Sorry, I can't make any test with Outlook.

Make a try with a variable instead (eventually a global variable).

Something like:
Code: [Select]
...
var wsBody: widestring;

...
  wsBody:=UTF8Decode(s);
  MailItem.Body:=wsBody;
...

vks

  • New Member
  • *
  • Posts: 33
Re: Emailing through outlook!
« Reply #4 on: March 06, 2015, 11:10:16 am »
Woah.. It worked!!
thank you so much :))

 

TinyPortal © 2005-2018