473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Failure sending mail

maliksleo
115 100+
hi i am using the following class for email sending but getting this error "Failure sending mail"

Expand|Select|Wrap|Line Numbers
  1. Imports System.Net.Mail
  2.  
  3. Public Class MailHelper
  4.     ''' <summary>
  5.     ''' Sends an mail message
  6.     ''' </summary>
  7.     ''' <param name="from">Sender address</param>
  8.     ''' <param name="recepient">Recepient address</param>
  9.     ''' <param name="bcc">Bcc recepient</param>
  10.     ''' <param name="cc">Cc recepient</param>
  11.     ''' <param name="subject">Subject of mail message</param>
  12.     ''' <param name="body">Body of mail message</param>
  13.     Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, _
  14.         ByVal subject As String, ByVal body As String)
  15.         ' Instantiate a new instance of MailMessage
  16.         Dim mMailMessage As New MailMessage()
  17.  
  18.         ' Set the sender address of the mail message
  19.         mMailMessage.From = New MailAddress(from)
  20.         ' Set the recepient address of the mail message
  21.         mMailMessage.To.Add(New MailAddress(recepient))
  22.  
  23.         ' Check if the bcc value is null or an empty string
  24.         If Not bcc Is Nothing And bcc <> String.Empty Then
  25.             ' Set the Bcc address of the mail message
  26.             mMailMessage.Bcc.Add(New MailAddress(bcc))
  27.         End If
  28.  
  29.         ' Check if the cc value is null or an empty value
  30.         If Not cc Is Nothing And cc <> String.Empty Then
  31.             ' Set the CC address of the mail message
  32.             mMailMessage.CC.Add(New MailAddress(cc))
  33.         End If
  34.  
  35.         ' Set the subject of the mail message
  36.         mMailMessage.Subject = subject
  37.         ' Set the body of the mail message
  38.         mMailMessage.Body = body
  39.  
  40.         'mMailMessage.Attachments.Add(New Net.Mail.Attachment(attachment))
  41.         ' Secify the format of the body as HTML
  42.         mMailMessage.IsBodyHtml = True
  43.         ' Set the priority of the mail message to normal
  44.         mMailMessage.Priority = MailPriority.Normal
  45.  
  46.         ' Instantiate a new instance of SmtpClient
  47.         Dim mSmtpClient As New SmtpClient("localhost")
  48.         ' Send the mail message
  49.         mSmtpClient.Send(mMailMessage)
  50.     End Sub
  51. End Class
  52.  
i am using my local server for testing and using local emails IDs for this instead of using gmail or yahoo that server sends email to local email IDs as i tested it through my PHP code but in asp.net case i am getting this error.
Please sugest me if some thing wrong in this code.
maliksleo
Apr 22 '09 #1
1 6113
Frinavale
9,735 Expert Mod 8TB
I'm not sure what's going on but just try something simple:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Net.Mail
  2.  
  3. Public Class MailHelper
  4.     ''' <summary>
  5.     ''' Sends an mail message
  6.     ''' </summary>
  7.     ''' <param name="from">Sender address</param>
  8.     ''' <param name="recepient">Recepient address</param>
  9.     ''' <param name="bcc">Bcc recepient</param>
  10.     ''' <param name="cc">Cc recepient</param>
  11.     ''' <param name="subject">Subject of mail message</param>
  12.     ''' <param name="body">Body of mail message</param>
  13.     Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, _
  14.         ByVal subject As String, ByVal body As String)
  15.         ' Instantiate a new instance of MailMessage
  16.         Dim mMailMessage As New MailMessage()
  17.  
  18.         ' Set the sender address of the mail message
  19.         mMailMessage.From = New MailAddress(from)
  20.         ' Set the recepient address of the mail message
  21.         mMailMessage.To.Add(New MailAddress(recepient))
  22.  
  23.         '' Check if the bcc value is null or an empty string
  24.         'If Not bcc Is Nothing And bcc <> String.Empty Then
  25.         '    ' Set the Bcc address of the mail message
  26.         '    mMailMessage.Bcc.Add(New MailAddress(bcc))
  27.         'End If
  28.  
  29.         ' Check if the cc value is null or an empty value
  30.         'If Not cc Is Nothing And cc <> String.Empty Then
  31.         '    ' Set the CC address of the mail message
  32.         '    mMailMessage.CC.Add(New MailAddress(cc))
  33.         'End If
  34.  
  35.         ' Set the subject of the mail message
  36.         mMailMessage.Subject = subject
  37.         ' Set the body of the mail message
  38.         mMailMessage.Body = body
  39.  
  40.         'mMailMessage.Attachments.Add(New Net.Mail.Attachment(attachment))
  41.         ' Secify the format of the body as HTML
  42.         'mMailMessage.IsBodyHtml = True
  43.         ' Set the priority of the mail message to normal
  44.         'mMailMessage.Priority = MailPriority.Normal
  45.  
  46.         ' Instantiate a new instance of SmtpClient
  47.         Dim mSmtpClient As New SmtpClient("localhost")
  48.         ' Send the mail message
  49.         mSmtpClient.Send(mMailMessage)
  50.     End Sub
  51. End Class
  52.  

If this works, start uncommenting the stuff that doesn't work to see what's causing the problem.
Apr 22 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: gudia | last post by:
I am using CDO to email a file as an attachment. The receiver receives the file, but when he opens the file (tried using both Acrobat Reader 6 and 5), he gets "There was an error opening this...
14
by: Bernie Yaeger | last post by:
OK - I'm very close. I'm running a console app on a server and it fails with cdo .message failure. It's a simple email routine which works fine on my development pc. Do you have any idea what...
3
by: HoustonComputerGuy | last post by:
I am working on getting my web applications moved to .Net 2.0 and am having some problems with System.Net.Mail. I get the following error when sending the mail: System.Net.Mail.SmtpException was...
2
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...
1
by: Chubbly Geezer | last post by:
Hi I am using the following code to send an email from within my program:- MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com"); theMailMessage.Body = "body email...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
2
by: Danny | last post by:
Hi all, Trying to send mail with System.Net.SmtpClient, using very simple code just for testing: SmtpClient smtp = new SmtpClient("mail.server.com", 25); smtp.Credentials = new...
2
by: shil | last post by:
Hi all, I'm using System.Net.Mail (Framework 2.0) to send emails on scheduled basis. This works great on Windows 2000 server. Rently we have upgraded our servers to Windows 2003. Since then some...
9
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...
5
by: Don Quijote de Nicaragua | last post by:
Hi, everyone I try to send a simple e-mail witch this Code, but always send me a error messages: "ERROR: Failure sending mail." Thansk You. Don Quijote de Nicaragua. Elder Soto. Dim correo As...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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,...
0
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
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,...

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.