473,513 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending an email in VB 2005

Hi Guys,

I have been trying to update my existing email routine within my .net
v2 web app website, I currently have the following code:

Dim GroupMailSender As New
SmtpClient(ConfigurationManager.AppSettings("Mail. SMTP"))

Dim GroupFrom As MailAddress = New MailAddress("X@X.uk")
Dim GroupTo As MailAddress = New MailAddress("T@T.uk")
Dim GroupEmail As MailMessage = New MailMessage(GroupFrom,
GroupTo)

GroupEmail.Subject = txtGroupSubject.Text
GroupEmail.Body = txtGroupMessage.Text

Try
GroupMailSender.Send(GroupEmail)
Catch ex As Exception
txtGroupMessage.Text &= ex.ToString
End Try

lblGroupFeedback.Text = "Mail Message Has Been Sent"

clearGroupPanel()

This code works fine, although I am trying to change the from address
to recognise the user currently using the system. The code below picks
up the users identity and retrieves their email from the database:

Dim user As New UserEntity
Session("UserEmail") = user.Email

However the problem is when I have attempted to use this variable
rather than a fixed email address, for example (code replacement):

Dim user As New UserEntity
Session("UserEmail") = user.Email

dim testEmail as string = Session("UserEmail")

Dim GroupFrom As MailAddress = New MailAddress(testEmail)

However I get the following error, " Unable to cast object of type
'System.String' to type 'System.Net.Mail.MailAddress'.".

I have also tried changing the variable type from a string to a
system.net.mail.mailmessage, but i still encounter the same error.

Has anyone encountered and overcome this problem?? Any help would be
very much appreciated.

Thanks,

Simon

Jun 19 '07 #1
1 2471
This is how I do it and it works just fine:

Dim body as string = "Whatever"

Dim subject as string = "Subject"

Dim fromAddress As New System.Net.Mail.MailAddress(fromAddy)

Dim toAddress As New System.Net.Mail.MailAddress(toAddy)

Dim msg As New System.Net.Mail.MailMessage

msg.From = fromAddress

msg.To.Add(toAddress)

msg.CC.Add(ccAddress)

msg.Subject = Subject

msg.Body = body

msg.IsBodyHtml = True

Dim mailSender As New System.Net.Mail.SmtpClient()

mailSender.Host = "myhost.com"

mailSender.Send(msg)

Hope it helps...

"si_owen" <s.****@sstaffs.gov.ukwrote in message
news:11**********************@u2g2000hsc.googlegro ups.com...
Hi Guys,

I have been trying to update my existing email routine within my .net
v2 web app website, I currently have the following code:

Dim GroupMailSender As New
SmtpClient(ConfigurationManager.AppSettings("Mail. SMTP"))

Dim GroupFrom As MailAddress = New MailAddress("X@X.uk")
Dim GroupTo As MailAddress = New MailAddress("T@T.uk")
Dim GroupEmail As MailMessage = New MailMessage(GroupFrom,
GroupTo)

GroupEmail.Subject = txtGroupSubject.Text
GroupEmail.Body = txtGroupMessage.Text

Try
GroupMailSender.Send(GroupEmail)
Catch ex As Exception
txtGroupMessage.Text &= ex.ToString
End Try

lblGroupFeedback.Text = "Mail Message Has Been Sent"

clearGroupPanel()

This code works fine, although I am trying to change the from address
to recognise the user currently using the system. The code below picks
up the users identity and retrieves their email from the database:

Dim user As New UserEntity
Session("UserEmail") = user.Email

However the problem is when I have attempted to use this variable
rather than a fixed email address, for example (code replacement):

Dim user As New UserEntity
Session("UserEmail") = user.Email

dim testEmail as string = Session("UserEmail")

Dim GroupFrom As MailAddress = New MailAddress(testEmail)

However I get the following error, " Unable to cast object of type
'System.String' to type 'System.Net.Mail.MailAddress'.".

I have also tried changing the variable type from a string to a
system.net.mail.mailmessage, but i still encounter the same error.

Has anyone encountered and overcome this problem?? Any help would be
very much appreciated.

Thanks,

Simon

Jun 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
9012
by: Christophe Cerbourg | last post by:
hi, Bonjour, I'm using PHPMailer class to send mails and it works fine for HTML ones. But I can't manage to send correctly a text formatted mail... I tried this : - $message = "first...
0
522
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
4
2954
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
5
2608
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
4
3558
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
13
3184
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
3
7696
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce...
2
10129
by: HK | last post by:
In VB.NET, I'm getting the exception "failure sending mail". I'm running VS 2005 on XP Home. This is a new install on a new PC. I've never had email problems with VS 2003, and there I could...
14
4636
by: John | last post by:
Hi How does one send email from within a vb.net app? Thanks Regards
9
3434
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7106
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7534
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.