Solved

Insert signature to email via visual basic for application

Posted on 2006-06-20
13
264 Views
Last Modified: 2013-11-25
I like to insert a signature (name, telefon, ... not signature like certifcate) in a email via visual basic for application
0
Comment
Question by:ibeling
  • 5
  • 3
  • 2
13 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16943530
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
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16944648
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.
0
 

Author Comment

by:ibeling
ID: 16949007
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" ...
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 16951584
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.
0
 

Author Comment

by:ibeling
ID: 16951637
It will help me to save time if you can make a little code snippet, to start.

Thanks
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Expert Comment

by:alainbryden
ID: 16951745
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.
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16953606
If you need outlook code, take a look here:
http://www.outlookcode.com/
0
 

Author Comment

by:ibeling
ID: 16953755
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
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 16953996
Well ibeling, according to your description the solution is this:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String

SignatureName = 'SEE BELOW

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

'Attatch the signature


What that code will do is locate the signature, and copy it to that string SIGNATURE, then you need to take that string and append it to the end of the email message. I know you can do that on your own.


The only problem now is how do you get the SignatureName? This is almost always called "Name.txt" But the user is able to rename his signatures and have more than one. The only solution is to let the user browse and select a user name. Do to that you need to add In Project components the Windows Common Dialog Control, and drag one onto your form, and name it "FileDialog".

Once you do this add these lines of code before my code:

   Dim SignatureLocation

    FileDialog.DialogTitle = "Load A Signature"
    FileDialog.DefaultExt = "txt"
    FileDialog.Filter = "Text Documents (*.txt)|*.txt"
    FileDialog.Flags = &H1004 ' This flag means only existing names are allowed and no read-only
    FileDialog.InitDir = "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\"
    FileDialog.ShowOpen     'User selects the file to open

    Open FileDialog.FileName For Input As #1

And then the rest of the code is the same and you will have their signature. Try it out. You will see it works 100%. I already tested it myself. If you want, you can store this signature so that they only have to load it once and then it always uses the same signature again. I'm sure you can handle this much.


Enjoy.
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17293295
once taking reccomendations, if a response isn't given, I would like to suggest that I gave a working solution.

Alain
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now