Link to home
Start Free TrialLog in
Avatar of ibeling
ibeling

asked on

Insert signature to email via visual basic for application

I like to insert a signature (name, telefon, ... not signature like certifcate) in a email via visual basic for application
Avatar of alainbryden
alainbryden
Flag of Canada image

If you are sending through another email client, Only the email client can define a reoccuring signature. If you wish to add a signature, than you must concatonate whatever the signature is supposet to be to the end of the message. So;

message As String
signature As String
message = message & vbNewLine & vbNewLine & signature
Avatar of cool12399
cool12399

are you actually writing an e-mail application? or you mean just appending a signature?
if the latter, yes, simply take your message, append the signature, and then pass the new
message to your procedure.
Avatar of ibeling

ASKER

I have already some signature defined in Outlook. (ones for internal use, ones for external, ones for private). So maybe my question should be more "how can i access the signature collection" ...
No. The way outlook inserts a signature is to take the stored signature and code it directly into the html of the email, so the only way you can insert the signature is to do the same. There is no field such as OutlookApp.signature("Name") or anything like that that you can use.

As for where outlook stores it, all signatures are stored in HTML, Rich Text AND .txt format under

 C:\Documents and Settings\[username]\Application Data\Microsoft\Signatures

So if you know the name of the signature. You can concatonate as follows.

Open up C:\Documents and Settings\[username]\Application Data\Microsoft\Signatures\myName.txt (or .htm or .rtf )
Copy Everything
Paste it into your message.
This can easily be automated, let me know if you can't figure it out.
Avatar of ibeling

ASKER

It will help me to save time if you can make a little code snippet, to start.

Thanks
Well I have no idea how you're writing you email in Visual basic, but to access that file you say:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String
username =  'Fill this in yourself
SignatureName =  Name 'Fill this in yourself

Open "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\" & SignatureName & ".txt" For Input As #1

SIGNATURE = vbNullString
Do While Not EOF(1)
    Line Input #1, text
    SIGNATIRE = SIGNATURE & vbNewLine & text
Loop
Close #1   'Closes the signature file you opened

'At this point you have the entire signature stored as a string (SIGNATURE). Do with it what you will. Attatch it to the end of the message is probably the best thing.

MessageTextBox.text = MessageTextBox.text & vbNewLine & SIGNATURE

'Now send the message, complete with signature and all.
If you need outlook code, take a look here:
http://www.outlookcode.com/
Avatar of ibeling

ASKER

We generate Emails from a application.
Depend of the system variable USERNAME, we want add his signature.
Yes it is strange. But the customer wishes are our job.
Thanks for help.

Regards Ingo
ASKER CERTIFIED SOLUTION
Avatar of alainbryden
alainbryden
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
once taking reccomendations, if a response isn't given, I would like to suggest that I gave a working solution.

Alain