Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open Default Email and populate Message with Text from VB.NET

Posted on 2004-08-19
8
Medium Priority
?
356 Views
Last Modified: 2006-11-17
Hi Experts!

I need a button in an ASP.NET web app that when clicked will open the users default mail application and populate the body of the email message with text from the current webform.. anydirection on how do do this will be greatly appreciated
thanks ;)
0
Comment
Question by:jcraun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 11844380
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Me.Button1.Text = "Send Mail"
Me.Button1.Attributes("onClick") =
"window.location='mailto:bla@bla.com?subject=Iouri demo&body=bla bla bla';"
End If
End Sub
0
 

Author Comment

by:jcraun
ID: 11844568
Neat thanks!.. okay... so what if I need the body of the message to be a concatention of the input of several textboxes from the form that the send email button is on?
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 11844927
In this case instead of
...body=bla bla bla';"
use
...body=" & txt1.text & " " & txt2.text & "';"
0
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

Author Comment

by:jcraun
ID: 11845764
Okay getting closer.... Only problem is:

1. how do you format the body?
I tried
body=" & txt1.text & " <br> " & txt2.text & "';"
and I got:   bob <br> nancy
instead of:
bob
nancy

2. Is there any way to get this to work when it is not in the Page Load event because the user needs to fill out the form/textboxes and then submit the email..

Thanks for your patience!
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 1500 total points
ID: 11846015
it's either
body=" & txt1.text & "  " & txt2.text & "';"  ' to have space between txtboxes
or
body=" & txt1.text & Environment.NewLine  & txt2.text & "';"

2. It is not in Page load event. In Page Load event you only attach an atribute to the button click event. It will work on Button1_Click event

Another Approach is to register the JS under the button clcik event

   Me.RegisterStartupScript("key", _
  "<script language='javascript'>window.location=mailto:bla@bla.com?subject=Iouri demo&body=bla bla bla';"</script>")

0
 

Author Comment

by:jcraun
ID: 11846654
I think I could eventually make that way work but I am not very familiar w/JS and I need a lot of formatting in the email such as bold, and line breaks etc... and these are long emails.....

here is and example of the way I have been sending emails.. but if I could just make it Display rather than send would be my best option. Do you know how to do it this way? Or what I would have to add?

******************************************************************************************
            Dim genfunc As New GeneralFunctions()
            Dim name As String
            name = genfunc.GetFname(ddlOwner.SelectedItem.ToString)
             strEmailrecip = genfunc.GetEmail(strOwner)

            'send an email when message is submitted
            Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()
            mailMessage.From = "do_not_reply@test.com"
            mailMessage.To = strEmailrecip
            mailMessage.Subject = "New Crit_Sit Task submitted"
            mailMessage.BodyFormat = System.Web.Mail.MailFormat.Html
            mailMessage.Body = "<font face=arial size=2>"
            mailMessage.Body &= strMessage & "<br><br><br>"
            mailMessage.Body &= strMessage1 & "<br>"
            mailMessage.Body &= "<b>" + "Task Description:" + "</b>" + "<br>"
            mailMessage.Body &= txtTaskDescription.Text + "<br>"
            mailMessage.Body &= "<b>" + "Due Date:" + "</b>" + "<br>"
            System.Web.Mail.SmtpMail.SmtpServer = "test.test.com"
            System.Web.Mail.SmtpMail.Send(mailMessage)
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 11850779
WHat you are doing is absolutely different from what you asked. YOur code sends SMTP email, that runs as Default SMTP server on your server. Server will be sending email, not a client
You asked to open the default email client on th eclient machine
Both approaches are good and you have to decide which one you prefer
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 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