Rudolph Scott

I use the following code to assign values to already defined fileds

Dim theStringBuilder As New Text.StringBuilder() ' String of characters

theStringBuilder.Append(mailto:MYWORKPLACE@DOMAIN)

theStringBuilder.Append("&subject=PhoneCall")

theStringBuilder.Append("&body=my body message")

However, when I want to assign a value to one of my Custom fields like Caller which is just a textbox I do not see any values assigned. Could someone tell me how to do this Thanks.



Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

jgalley

Can you explain what you are attempting to do in a little more detail

When you say "I use the following code to assign values to already defined fileds" I am not sure what you are talking about. the code you provide assigns some text to a variable. Do you then want to assign the variable to form fields or specifically a textbox

TextBox1.Text = theStringBuilder.ToString()

If this is not what you are looking for then I think more explaination is needed.





Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Rudolph Scott

The textboxes are on an Outlook 2007 new e-mail form. The default boxes are Subject, cc, Body, things like that. I additionally added some more textboxes to this form and named them (names like Caller, Surname,Building, etc, etc). Just like my code assigns the text value 'PhoneCall' to the subject box and displays the value in the subject box when the new mail message form loads, I want to assign a values to my custom boxes. For instance, I have a box called 'Caller' and I want to assign a text value to it and have it displayed in this box. I am doing this using Visual Basic in Visual Studio 2005.

Is it possible to use stringbuilder in this case Or do I need to use another method





Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Martin Xie - MSFT

Rudolph Scott wrote:

The textboxes are on an Outlook 2007 new e-mail form. The default boxes are Subject, cc, Body, things like that. I additionally added some more textboxes to this form and named them (names like Caller, Surname,Building, etc, etc). Just like my code assigns the text value 'PhoneCall' to the subject box and displays the value in the subject box when the new mail message form loads, I want to assign a values to my custom boxes. For instance, I have a box called 'Caller' and I want to assign a text value to it and have it displayed in this box. I am doing this using Visual Basic in Visual Studio 2005.

Is it possible to use stringbuilder in this case Or do I need to use another method

Hi Rudolph,

Please check the System.Net.Mail.MailMessage Class.

http://msdn2.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx

It represents an e-mail message that can be sent using the SmtpClient class.

The MailMessage class has these associated properties as below.

When an e-mail message is to be sent, basic properties will be specified, likewise, when you receive an e-mail message, you can directly retrieve relevant property value to your TextBox control.

SmtpClient can be used to send Email message.

PopClient can be used to retrieve Email messages.

Mail part

Property

Sender

From

Recipient

To

Carbon copies (CC)

CC

Blind carbon copies (BCC)

Bcc

Attachments

Attachments

Subject

Subject

Message body

Body

Send Email sample.

Public Shared Sub CreateMessageWithAttachment(ByVal server As String)
' Specify the file to be attached and sent.
Dim file As String = "data.xls"
' Create a message and set up the recipients.
Dim message As MailMessage = New MailMessage("jane@contoso.com", "ben@contoso.com", "Quarterly data report.", "See the attached spreadsheet.")


'Create the file attachment for this e-mail message.
Dim data As Attachment = New Attachment(file, MediaTypeNames.Application.Octet)



' Add the file attachment to this e-mail message.
message.Attachments.Add(data)


'Send the message.
Dim client As SmtpClient = New SmtpClient(server)


' Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials
client.Send(message)
End Sub

References:

Send Email sample

POP3 Email Client (.NET 2.0)

Sending and Receiving Email

Regards,

Martin






Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Rudolph Scott

Thanks for your reply Martin. I basically need to put the approriate values to my custom text boxes before the e-mail is sent, not when I receive the e-mail. The sample code you sent me didn't show me how to specify a value to a textbox. Could you send me an example which does if you have one Thanks in advance.





Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Martin Xie - MSFT

Rudolph Scott wrote:

I basically need to put the approriate values to my custom text boxes before the e-mail is sent. The sample code you sent me didn't show me how to specify a value to a textbox.

Please assign the approriate values to your custom TextBoxes in Form1_Load event.

Code Block

Imports System.Text

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TextBox1.Text = "PhoneCall"

TextBox2.Text = "my body message"

Dim theStringBuilder As New StringBuilder() ' String of characters

theStringBuilder.Append(mailto:MYWORKPLACE@DOMAIN)

theStringBuilder.Append("&subject=" + TextBox1.Text)

theStringBuilder.Append("&body=" + TextBox2.Text)

End Sub

Is this what you want




Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Rudolph Scott

Kind of. Mt Textboxes are not the default ones like 'subject'. My ones have different names like 'Caller', etc. I have tried to use the following line in my Visual Studio code;

theStringBuilder.Append("&Caller.Text=Rudolph");

but nothing appears in the box! I don't have a form load as such. My Visual Studio code opens Outlook 2007 then I choose a menu item from the 'Tools' menu whcih opens a new E-mail form. This is when I want the data to go into my custom textboxes. Values seem to go in for the 'mailto' and subject and body textboxes, but none of the other fields I have.

Any more suggestions





Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Martin Xie - MSFT

Hi Rudolph,

The idea is: you need to create/add custom properties (specified by Name and Type) to e-mail messages and extract relevant property value into custom TextBox control.

To open new email window in Outlook, usually we use the following code.

Code Block

Dim MsgBuilder As New System.Text.StringBuilder
MsgBuilder.Append("mailto:melroy@testmail.com")
MsgBuilder.Append(&cc=testcc@testcc.com,testcc1@testcc.com)
MsgBuilder.Append("&bcc=testcc@testbcc.com,testcc1@testbcc.com")
MsgBuilder.Append("&subject=this is test subject")
MsgBuilder.Append("&body=this is test body")
MsgBuilder.Append("&Attach=c:\mailattach.txt")

System.Diagnostics.Process.Start(MsgBuilder.ToString())

Sample: Open Default mail client in .NET

As you can see, such properties as Subject, Cc, Bcc, Body, Attach are built-in.

By default, only properties that are already created in the default mail delivery store are preserved for incoming e-mail messages.

KB article: Changes to custom properties in Outlook

Add custom fields programmatically

Various APIs can be used to programmatically add custom fields to items. To do this, use the UserProperties.Add method in the Outlook object library ("Outlook.Application"). The following code illustrates this best practice.

Set myProp = myItem.UserProperties.Add("MyPropName", olText)

Please check these documents:

Best Practices for Getting and Setting Properties

Creating a Property

Setting the Value of a Property

Getting the Value of a Property

It's likely to get better answer at VSTO forum.

MSDN Forums Visual Studio Tools for Office Visual Studio Tools for Office

Questions on using Visual Studio 2005 Tools for the Microsoft Office System to create managed code solutions in Excel 2003, Word 2003, InfoPath 2003, & Outlook 2003

Best regards,

Martin






Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Rudolph Scott

I have looked at this. The problem is that I need to get the code to work in VB and all the examples I have seen are for VBA! It's a pity stringbuilder can't be used to set the values in VB as this would suit me fine. Do you know of a way to get VBA code to work within a Visual Studio VB environment Thanks in advance.





Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Adminstrators






Re: Visual Basic Express Edition How to get stringbuilder to assign values to custom textboxes on a New e-mail window

Adminstrators

Rudolph Scott wrote:

I use the following code to assign values to already defined fileds

Dim theStringBuilder As New Text.StringBuilder() ' String of characters

theStringBuilder.Append(mailto:MYWORKPLACE@DOMAIN)

theStringBuilder.Append("&subject=PhoneCall")

theStringBuilder.Append("&body=my body message")

However, when I want to assign a value to one of my Custom fields like Caller which is just a textbox I do not see any values assigned. Could someone tell me how to do this Thanks.