Sending Mail  
Author Message
BilalShouman





PostPosted: .NET Framework Networking and Communication, Sending Mail Top

This is my code

Dim oMsg As New MailMessage
Dim SMTPEngine As SmtpMail



oMsg.Subject = "test"
oMsg.Body = "test"
oMsg.Priority = MailPriority.High
oMsg.BodyFormat = Mail.MailFormat.Text

SmtpMail.SmtpServer.Insert(0, config.SMTPIP)
SMTPEngine.Send(oMsg)

when im stepping through this code eveything is working fine, but im not receiving any email, i have no firewall, and the smtpIp is working fine on a web application

why im not receiving anything

Please help



.NET Development31  
 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Sending Mail Top

could be a number of reasons. Do you not get any errors Which version of .NET Framework are you using if you are using .NET 2.0 use the System.Net.Mail namespace and classes.

you may need to provide credentials to the Smtp class in order to authenticate. You also dont need a .ToString() at the end of your From and To properties



 
 
Friendly Dog





PostPosted: .NET Framework Networking and Communication, Sending Mail Top

Use SmtpClient. Here's very simple example

SmtpClient client = new SmtpClient("www.foo.com");
com", "Friendly Dog");
");
MailMessage message = new MailMessage(from, to);
message.Body = "This is some HTML text <a href=\"www.foo.com\">FOO</a>";
message.Subject = "You are invited";
message.IsBodyHtml = true;
client.Send(message);
message.Dispose();

www.foo.com should be your SMTP host server

Here's a link about how to setup SMTP on IIS

http://msdn2.microsoft.com/en-us/library/8b83ac7t(vs.80).aspx

and more complete code sample

http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx



 
 
BilalShouman





PostPosted: .NET Framework Networking and Communication, Sending Mail Top

Im using vb.net 2003

im not getting any errors..
and Im not receiving any emails

please help


 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Sending Mail Top

if this works in a web app but not a winform app, one thing does come to mind - your anti virus software. Some do block sending emails from an application, others wait until the application is closed to send the email. I would also check to see if in your junk email inbox has those emails incase if it filters it out.

The way I did it in a WinForm app in .NET 2003 was simply to add a reference to System.Web then import the namespace. Secondly the code was like this:

Dim theMailMessage as new System.Web.Mail.MailMessage()

theMailMessage.Body = "hi"

Dim theSMTP as System.Web.Mail.SmtpMail()

theSMTP.Server = "IP.Address.Of.Server"

theSMTP.Send(theMailMessage)

of course its similar/same as yours. I wouldnt understand what could not cause it to get there. Its sending ok as you are saying but not recieving... bit of a puzzler. Again, I would disable your AV Software and send it, and check the junk email inbox too