This code snippet works fine (vs 2005)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim message As New MailMessage()
Try
message.From = New MailAddress("my****@mydomain.com")
message.To.Add(New MailAddress("my****@mydomain.com"))
message.Subject = "Test"
message.Body = "Test body"
Dim Client As New SmtpClient()
Client.Host = "mail.mydomain.com"
Client.Port = 25
Dim LoginCredentials As New
System.Net.NetworkCredential("my****@mydomain.com" , "mypassword")
Client.UseDefaultCredentials = False
Client.Credentials = LoginCredentials
Client.Send(message)
Catch ex As SmtpException
MsgBox(ex.Message)
End Try
End Sub
Yet the following which is EXACTLY the same except for the fact that the
values are passed to it from a call to a sub does not work, yet I have
checked consistently that the values when stepping thru in the debugger are
exactly the same in the equivalent line of code. Here's code snippet 2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SendMail("mail.mydomain.com", "my****@mydomain.com", "sgiimsinc",
"my****@mydomain.com", "my****@mydomain.com", "subject", "body")
End Sub
Sub SendMail(ByVal SMTPServerName As String, ByVal SMTPUsername As
String, ByVal SMTPPassword As String, _
ByVal ThisSenderEmail As String, _
ByVal RecipientEmail As String, _
ByVal Subject As String, ByVal Body As String)
Dim message As New MailMessage()
Try
message.From = New MailAddress(ThisSenderEmail)
message.To.Add(New MailAddress(RecipientEmail))
message.Subject = Subject
message.Body = Body
Dim Client As New SmtpClient()
Client.Host = SMTPServerName
Client.Port = 25
Dim LoginCredentials As New
System.Net.NetworkCredential(SMTPUsername, SMTPPassword)
Client.UseDefaultCredentials = False
Client.Credentials = LoginCredentials
Client.Send(message)
Catch ex As SmtpException
'Log the exception
MsgBox(ex.Message)
End Try
End Sub
There are no exceptions thrown by code snippet two. It just does not send
the e-mail. The code is all on the same test form. its just called either by
button one which executes it directly with the values hardcoded in or by
button 2 which calls the sendmail mail sub and passes it EXACTLY the same
parameters as the hardcoded values in snippet 1. I quadruple checked the
values of the passed parameters single stepping thru the executing code,
they ARE the same.
Does anyone have any idea why snippet 2 does not work and hpow to workaround
this?
Thanks for your help
Bob 4 1179
Bob wrote: There are no exceptions thrown by code snippet two. It just does not send the e-mail.
In my (limited) experience, that seems to mean that the .To address was not
valid.
Just try changing each value, one at a time, from hard-coded to being a
variable and then see which one breaks it.
Also, does MailMessage.To (etc.) accept a string if you want to simplify it
by taking out the New MailAddress? Hmmm... does a MailAddress have a .Valid
property or some such in .NET 2.0?
Andrew
Thanks andrew I still am stumped but I will try calling the procedure that
has hardcoded addresses in it and pass it each parameter in turn to see
which one breaks it. I'll share the results.
"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Bob wrote: There are no exceptions thrown by code snippet two. It just does not send the e-mail.
In my (limited) experience, that seems to mean that the .To address was not valid.
Just try changing each value, one at a time, from hard-coded to being a variable and then see which one breaks it.
Also, does MailMessage.To (etc.) accept a string if you want to simplify it by taking out the New MailAddress? Hmmm... does a MailAddress have a .Valid property or some such in .NET 2.0?
Andrew
It gets weirder.
I found that I could get the sending to work ONLY if my default email client
(outlook 2003) on this computer was closed!
If I do not close my outlook 2003, use my code to send using either the
hardcoded parameters sub or the sub to which I pass parameters, nothing gets
sent to the smtp server. If I close Outlook 2003, send my messages using my
code, it works fine. I can then open Outlook 2003 and retrieve my test
message from the server. It looks like you can only have one active e-mail
client at a time on a given computer.
Does anyone know if this is so?
Bob
"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Bob wrote: There are no exceptions thrown by code snippet two. It just does not send the e-mail.
In my (limited) experience, that seems to mean that the .To address was not valid.
Just try changing each value, one at a time, from hard-coded to being a variable and then see which one breaks it.
Also, does MailMessage.To (etc.) accept a string if you want to simplify it by taking out the New MailAddress? Hmmm... does a MailAddress have a .Valid property or some such in .NET 2.0?
Andrew
Not immediately related to the problem you're seeing, but in trying to find
out why I was having problems with authetication, I found that if
UseDefaultCredentials was not set to false BEFORE assigning credentials to
the SmtpClient object, the values of credentials in the object were null
immediately before sending.
"Bob" wrote: This code snippet works fine (vs 2005) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim message As New MailMessage() Try message.From = New MailAddress("my****@mydomain.com") message.To.Add(New MailAddress("my****@mydomain.com")) message.Subject = "Test" message.Body = "Test body" Dim Client As New SmtpClient() Client.Host = "mail.mydomain.com" Client.Port = 25 Dim LoginCredentials As New System.Net.NetworkCredential("my****@mydomain.com" , "mypassword") Client.UseDefaultCredentials = False Client.Credentials = LoginCredentials Client.Send(message) Catch ex As SmtpException MsgBox(ex.Message) End Try End Sub
Yet the following which is EXACTLY the same except for the fact that the values are passed to it from a call to a sub does not work, yet I have checked consistently that the values when stepping thru in the debugger are exactly the same in the equivalent line of code. Here's code snippet 2 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click SendMail("mail.mydomain.com", "my****@mydomain.com", "sgiimsinc", "my****@mydomain.com", "my****@mydomain.com", "subject", "body") End Sub
Sub SendMail(ByVal SMTPServerName As String, ByVal SMTPUsername As String, ByVal SMTPPassword As String, _ ByVal ThisSenderEmail As String, _ ByVal RecipientEmail As String, _ ByVal Subject As String, ByVal Body As String)
Dim message As New MailMessage()
Try message.From = New MailAddress(ThisSenderEmail) message.To.Add(New MailAddress(RecipientEmail)) message.Subject = Subject message.Body = Body Dim Client As New SmtpClient() Client.Host = SMTPServerName Client.Port = 25 Dim LoginCredentials As New System.Net.NetworkCredential(SMTPUsername, SMTPPassword) Client.UseDefaultCredentials = False Client.Credentials = LoginCredentials Client.Send(message) Catch ex As SmtpException 'Log the exception MsgBox(ex.Message) End Try End Sub There are no exceptions thrown by code snippet two. It just does not send the e-mail. The code is all on the same test form. its just called either by button one which executes it directly with the values hardcoded in or by button 2 which calls the sendmail mail sub and passes it EXACTLY the same parameters as the hardcoded values in snippet 1. I quadruple checked the values of the passed parameters single stepping thru the executing code, they ARE the same.
Does anyone have any idea why snippet 2 does not work and hpow to workaround this?
Thanks for your help Bob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jerz |
last post by:
Hi,
I tried upgrading my version of PHP to 4.3.2 and now all of my pages are
returning the following for nearly every variable:
Notice: Use of undefined constant sopen - assumed 'sopen' in...
|
by: Jim Dawson |
last post by:
I was writing a subroutine to extract fields from lines of text when I
ran into an issue. I have reproduced this error on Perl 5.8 on AIX,
5.8 on Linux and 5.6 on Windows.
############### CUT...
|
by: Chris Mantoulidis |
last post by:
I see some really weird output from this program (compiled with GCC
3.3.2 under Linux).
#include <iostream>
using namespace std;
int main() {
char *s;
s = "test1";
cout << "s = " << s << "...
|
by: Les Paul |
last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's
just like a Wiki page, but my own very simple version. It's a page full
of plain old HTML content, and then at the bottom,...
|
by: Jitesh Sinha |
last post by:
Hi,
I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal
behaviour of System.Web.mail class. It was truncating the message body
after 3,071 character. The code i was testing...
|
by: ZorpiedoMan |
last post by:
This is so weird, and I cannot even isolate the cause enough to give any
clues as to how to reproduce the error, so this is probably a real shot
in the dark...
BUT, has anyone ever run into a...
|
by: Bob |
last post by:
Vs2005 - Framework2. Just to let all of you know. I have found that I can
not use an application to send e-mails using the system,net.mail namespace
while Outlook express is opened on the same...
|
by: ian |
last post by:
Hi, I've got the weirdest garbage collection problem - I'd appreciate any
advice you've got.
1. A class 'X' in a system I'm working on contains a reference to an
XmlDocument, populated via...
|
by: David Thole |
last post by:
Hey all,
I'm still very new at all this, but am going through the ASP.net 2.0
unleashed book, first chapter and trying to program my own little form
emailer for fun. I tried following the code...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |