473,672 Members | 2,450 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(Conf igurationManage r.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(Gro upFrom,
GroupTo)

GroupEmail.Subj ect = txtGroupSubject .Text
GroupEmail.Body = txtGroupMessage .Text

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

lblGroupFeedbac k.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("UserEm ail") = 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("UserEm ail") = user.Email

dim testEmail as string = Session("UserEm ail")

Dim GroupFrom As MailAddress = New MailAddress(tes tEmail)

However I get the following error, " Unable to cast object of type
'System.String' to type 'System.Net.Mai l.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 2474
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(fr omAddy)

Dim toAddress As New System.Net.Mail .MailAddress(to Addy)

Dim msg As New System.Net.Mail .MailMessage

msg.From = fromAddress

msg.To.Add(toAd dress)

msg.CC.Add(ccAd dress)

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.goog legroups.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(Conf igurationManage r.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(Gro upFrom,
GroupTo)

GroupEmail.Subj ect = txtGroupSubject .Text
GroupEmail.Body = txtGroupMessage .Text

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

lblGroupFeedbac k.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("UserEm ail") = 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("UserEm ail") = user.Email

dim testEmail as string = Session("UserEm ail")

Dim GroupFrom As MailAddress = New MailAddress(tes tEmail)

However I get the following error, " Unable to cast object of type
'System.String' to type 'System.Net.Mai l.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
9054
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 line*\n*second line"; - $message = "first line*\r\n*second line"; - $message = "first line*".chr(13).chr(10)*second line";
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 import mimetypes import os,string
4
2965
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 email by creating a text file, with content following certain format, and saving that file into the correct '..\mailroot\pickup' folder, and it is working fine
5
2625
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 depending on member expiration dates. When the form is submitted, the code loops through the form contents and sends an email to those members that meet the selected criteria. All this worked perfectly when I was sending text emails, but since I
4
3572
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 printer port. I've tried to help myself with this one but searching in the "Python Library Reference" that installed with my version, yielded nothing on the subject of either timing or parallel port.
13
3212
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 this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other...
3
7720
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 value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
2
10138
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 modify the SMTP settings in IIS. But with this install, there is no IIS (at least I can't find an IIS with MMC browsing the snap-ins). I suspect that is part of the problem but I don't know the solution and I have to be able to test sending email...
14
4646
by: John | last post by:
Hi How does one send email from within a vb.net app? Thanks Regards
9
3454
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 oSMTP.Send(oMailMessage) (in this line I am getting the above err)
0
8486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8406
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8932
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6240
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4230
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2821
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 we have to send another system
2
2064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.