473,657 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Failure sending mail

maliksleo
115 New Member
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 6135
Frinavale
9,735 Recognized Expert Moderator Expert
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
4704
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 document. The file is damaged and could not be repaired." (similar error on Acrobat Reader 5--Root object is missing) This pdf file opens fine on the workstation from where I am transmitting. I have tried other pdf files, but exact problem happens...
14
1610
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 would cause this? Thanks for any help. Bernie Yaeger
3
57631
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 unhandled by user code Message="Failure sending mail." Source="System" StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Net.Mail.SmtpClient.Send(String from, String
2
10137
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...
1
2469
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 message here"; theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment")); theMailMessage.Subject = "Subject here"; SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp"); theClient.UseDefaultCredentials = false;
2
6817
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 to fix this error. I am able to send messages sometimes both other times randomly following error appear EXCEPTION:
2
6085
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 System.Net.NetworkCredential("user", "password"); try {
2
2573
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 of the emails are failing from being sent to people. Ratio is like 1 in 30 are being failing, I thought it is the mail size issue and I have unchecked the mail size limit on SMTP server. Still I couldn't figure out why few are not going out.
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)
5
4684
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 New System.Net.Mail.MailMessage() correo.From = New System.Net.Mail.MailAddress("MyAco...@turbonett.com.ni")
0
8315
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
8734
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
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
5633
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
4164
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
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.