Web Mail
Web Mail
Web Mail
Web Mail
Web Mail
Web Mail Web Mail Web Mail Web Mail Web Mail Web Mail Web Mail Web Mail
Web Mail Web Mail
Web Mail
Go Back  Xtreme Visual Basic Talk > > > Web Mail


Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2005, 04:24 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default Web Mail


I'm getting a 'System.NullReferenceException' exception when using the following code. It seems to be because 'server' is not set (server = nothing), when the program runs. Normally I'd think it was just because it's not initialized, but "Sub New" is private in this class. I searched online but found that everyone is doing practically the exact same things as I am...I'm stuck. Does anyone have any ideas?
This is the code I'm using to send with:
Code:
Dim mail As New System.Web.Mail.MailMessage Dim server As System.Web.Mail.SmtpMail Dim attachment As System.Web.Mail.MailAttachment Try If txtAttachment.Text <> "" Then attachment = New System.Web.Mail.MailAttachment(txtAttachment.Text) Catch MessageBox.Show("Attachment was invalid.") End Try mail.To = txtTo.Text mail.From = txtFrom.Text mail.Subject = txtSubject.Text mail.Body = txtBody.Text mail.Attachments.Add(attachment) server.SmtpServer = "Localhost" server.Send(mail) btnSend.Enabled = False
I was thinking that maybe the SmtpServer I was passing it was invalid...but I don't think that would give me a 'System.NullReferenceException'. If so at least I know that that's it.
__________________
170 10101010 410 J31^170
Reply With Quote
  #2  
Old 10-10-2005, 04:58 PM
ALEX_0077's Avatar
ALEX_0077 ALEX_0077 is offline
Contributor
 
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
Default

http://www.systemwebmail.com/faq/4.3.1.aspx

Hopefully, this will help. If not, post back.
Reply With Quote
  #3  
Old 10-10-2005, 06:07 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

Thanks for your reply. I did see the link you gave when I searched, but the thing is that I am not sure whether or not my SMTPserver is what is causing the problem. My question is more like...Would I get a null reference exception if the SmtpServer I passed it is wrong? Or am I getting this error for another reason?
__________________
170 10101010 410 J31^170
Reply With Quote
  #4  
Old 10-10-2005, 08:58 PM
ALEX_0077's Avatar
ALEX_0077 ALEX_0077 is offline
Contributor
 
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
Default

What line is your debugger breaking on?
Reply With Quote
  #5  
Old 10-10-2005, 09:28 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

The second to last: "server.Send(mail)". The reason is that the variable "server" is nothing. I'm wondering if maybe it's equal to nothing because the SMTP is a problem or if it's something else. Like I said, I can't initialize it either.
__________________
170 10101010 410 J31^170
Reply With Quote
  #6  
Old 10-11-2005, 06:50 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Here is how I've done it:
Code:
Dim mail As New MailMessage mail.From = "someone@microsoft.com" mail.To = "someoneelse@microsoft.com" mail.Subject = "This is a test message" mail.Body = "This is a test message" mail.Attachments.Add(New MailAttachment(PathToFileHere)) SmtpMail.SmtpServer = "Path.To.Your.SMTP.Server" SmtpMail.Send(mail)
Make sure you have a valid SMTP server running on localhost if you set SmtpMail.SmtpServer = "Localhost". Also be sure you have Collaboration Data Objects for Windows 2000 (CDOSYS) installed.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #7  
Old 10-11-2005, 09:28 AM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

Right, thanks for that. I did try going about it that way as well, same thing though. I guess It has to be my SMTP server. As a confirmation of that though....assuming that my SMTP server wasn't working, is that the error I would get, a 'Null reference exception'?
Also, how do I find out if I have CDOSYS installed? Is it only for win2K?
__________________
170 10101010 410 J31^170
Reply With Quote
  #8  
Old 10-11-2005, 12:53 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

It would sound like a reasonable exception to me but the docs don't specifically mention what happens if you don't have an SMTP server setup.

According to MSDN (Link):
Quote:
Windows 2000 and Windows XP: CDOSYS is enabled by default.
Windows NT 4.0: CDO NTS must be installed from the Windows NT 4.0 SDK.
What version of Windows are you on? I assume when this mentions XP it means XP Pro.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #9  
Old 10-11-2005, 03:30 PM
Zumwalt Zumwalt is offline
Contributor
 
Join Date: Sep 2003
Location: Tampa, FL
Posts: 474
Default

I am already assuming you have imports for the system.web.mail

Code:
Public ReadOnly ATSmtpHost = ConfigurationSettings.AppSettings("smtphost") Function SendMail() 'Create an instance of the MailMessage class Dim objMM as New MailMessage() objMM.To = "someone@someaddress.com" objMM.From = "someone@someaddress.com" 'objMM.Cc = "someone@someaddress.com" 'objMM.Bcc = "someone@someaddress.com" 'Send the email in text format objMM.BodyFormat = MailFormat.Text '(to send HTML format, change MailFormat.Text to MailFormat.Html) 'Set the priority - options are High, Low, and Normal objMM.Priority = MailPriority.Normal 'Set the subject objMM.Subject = "" 'Set the body objMM.Body = "" 'Specify to use the default Smtp Server, any server that has SMTP and you are authorized to use it as a relay if its not the local pc, I store mine in the web.config under an SmtpHost key. SmtpMail.SmtpServer = ATSmtpHost 'Now, to send the message, use the Send method of the SmtpMail class SmtpMail.Send(objMM) End Function
Reply With Quote
  #10  
Old 10-11-2005, 04:34 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

How is that different than what was already posted?
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #11  
Old 10-11-2005, 06:03 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

Thanks again John. My version of Xp is actually XP Home. I'm going to go ahead assuming that my SMTP program isn't working then, do you have any recommendations for one I could try? The one I'm using is a not so great free one I found online. I could try looking for another one but if there are any recommendations I'll look into them.
__________________
170 10101010 410 J31^170
Reply With Quote
  #12  
Old 10-11-2005, 07:29 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Quote:
Originally Posted by by_m
Thanks again John. My version of Xp is actually XP Home. I'm going to go ahead assuming that my SMTP program isn't working then, do you have any recommendations for one I could try? The one I'm using is a not so great free one I found online. I could try looking for another one but if there are any recommendations I'll look into them.
Everything I've done was with an Exchange server so I can't reccomend something less expensive than that. I think you should look deeper into CDOSYS however and possibly look for an alternative to the built in email ability of the .NET framework because I'm not convinced that it will work on XP Home anyway.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #13  
Old 10-12-2005, 05:35 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

OK then, I will, thanks for your help.
__________________
170 10101010 410 J31^170
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Web Mail
Web Mail
Web Mail Web Mail
Web Mail
Web Mail
Web Mail Web Mail Web Mail Web Mail Web Mail Web Mail Web Mail
Web Mail
Web Mail
 
Web Mail
Web Mail
 
-->