Ad:
 
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 2302
  • ASP.NET RSS
Similar Threads
Oct 26th, 2006
0

Email Sending Problem in ASP.NET

Expand Post »
hello there i want to send an email in which user has selected an attachment to send. below is the code for it:

asp.net Syntax (Toggle Plain Text)
  1. [COLOR=#0000ff]
  2. Imports[/COLOR][COLOR=#000000] System.Web.Mail[/COLOR]
  3. [COLOR=#0000ff]Public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]Class[/COLOR][COLOR=#000000] WebForm1[/COLOR]
  4. [COLOR=#0000ff]Inherits[/COLOR] System.Web.UI.Page
  5. #[COLOR=#0000ff]Region[/COLOR] " Web Form Designer Generated Code "
  6. [COLOR=#008000]'This call is required by the Web Form Designer.
  7. [/COLOR]<System.Diagnostics.DebuggerStepThrough()> [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] InitializeComponent()
  8. [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
  9. [/COLOR][COLOR=#0000ff]Protected[/COLOR] [COLOR=#0000ff]WithEvents[/COLOR] txtToEmail [COLOR=#0000ff]As[/COLOR] System.Web.UI.WebControls.TextBox
  10. [COLOR=#0000ff]Protected[/COLOR] [COLOR=#0000ff]WithEvents[/COLOR] lbFiles [COLOR=#0000ff]As[/COLOR] System.Web.UI.WebControls.ListBox
  11. [COLOR=#0000ff]Protected[/COLOR] [COLOR=#0000ff]WithEvents[/COLOR] butOK [COLOR=#0000ff]As[/COLOR] System.Web.UI.WebControls.Button
  12. [COLOR=#008000]'NOTE: The following placeholder declaration is required by the Web Form Designer.
  13. [/COLOR][COLOR=#008000]'Do not delete or move it.
  14. [/COLOR][COLOR=#0000ff]Private[/COLOR] designerPlaceholderDeclaration [COLOR=#0000ff]As[/COLOR] System.Object
  15. [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] Page_Init([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] [COLOR=#0000ff]MyBase[/COLOR].Init
  16. [COLOR=#008000]'CODEGEN: This method call is required by the Web Form Designer
  17. [/COLOR][COLOR=#008000]'Do not modify it using the code editor.
  18. [/COLOR]InitializeComponent()
  19. [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
  20. [/COLOR]#[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Region
  21. [/COLOR][COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] Page_Load([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] [COLOR=#0000ff]MyBase[/COLOR].Load
  22. [COLOR=#008000]'Put user code to initialize the page here
  23. [/COLOR][COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
  24. [/COLOR][COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] butOK_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] butOK.Click
  25. [COLOR=#0000ff]Dim[/COLOR] TheMailMessage [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]New[/COLOR] MailMessage
  26. [COLOR=#0000ff]Dim[/COLOR] TheMailConnection [COLOR=#0000ff]As[/COLOR] SmtpMail
  27. [COLOR=#0000ff]Dim[/COLOR] TheAttachment [COLOR=#0000ff]As[/COLOR] MailAttachment
  28. [COLOR=#0000ff]Dim[/COLOR] TheItem [COLOR=#0000ff]As[/COLOR] ListItem
  29. TheMailMessage.From = "shahdhruv47@yahoo.com"
  30. TheMailMessage.To = txtToEmail.Text
  31. TheMailMessage.Subject = "File Request"
  32. TheMailMessage.Body = "Attached is the information " _
  33. & "you requested."
  34. [COLOR=#0000ff]For[/COLOR] [COLOR=#0000ff]Each[/COLOR] TheItem [COLOR=#0000ff]In[/COLOR] lbFiles.Items
  35. [COLOR=#0000ff]If[/COLOR] TheItem.Selected = [COLOR=#0000ff]True[/COLOR] [COLOR=#0000ff]Then
  36. [/COLOR]TheAttachment = [COLOR=#0000ff]New[/COLOR] MailAttachment( _
  37. Server.MapPath("/Email/C9/" & TheItem.Value))
  38. TheMailMessage.Attachments.Add(TheAttachment)
  39. [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
  40. [/COLOR][COLOR=#0000ff]Next
  41. [/COLOR]TheMailConnection.Send(TheMailMessage)
  42. [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
  43. End[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]Class
  44. [/COLOR]

and i am getting this error...........

Server Error in '/Email' Application.

The "SendUsing" configuration value is invalid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.

Source Error:

Line 46: End IfLine 47: NextLine 48: TheMailConnection.Send(TheMailMessage)Line 49: End SubLine 50: End Class
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dhruv Shah is offline Offline
17 posts
since Sep 2006
Oct 30th, 2006
0

Re: Email Sending Problem in ASP.NET

dude may be the problem coz u didnt add the next line to ur code.

SmtpMail.SmtpServer = "name of ur smtp server and often is localhost"

try that

sam
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
web_developer is offline Offline
84 posts
since Mar 2006
Oct 30th, 2006
0

Re: Email Sending Problem in ASP.NET

dude may be the problem coz u didnt add the next line to ur code.

SmtpMail.SmtpServer = "name of ur smtp server and often is localhost"

try that

sam
thank you so much. Now i am able to send mails, but the problem i noticed is that the mail is going to the BULK folder of the person whose email address i am writing in TO field, and also when i specified CC field and a email address then mail goes to the INBOX folder. What is the reason behind this.Plz.
So do you have any solution for this.
Last edited by Dhruv Shah; Oct 30th, 2006 at 2:11 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dhruv Shah is offline Offline
17 posts
since Sep 2006
Oct 31st, 2006
0

Re: Email Sending Problem in ASP.NET

dude

ofcourse the mail will reach the bulk mail because ur server isnt known to the server u r sending the mail.

u can do the thing to make the mail goes directly to the inbox but i dont know it and i heard it ****ing hard. u have to play with some protocols and other shits.
my advice to u is to be happy with wht u got.

sam
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
web_developer is offline Offline
84 posts
since Mar 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: DropDownList
Next Thread in ASP.NET Forum Timeline: Messagebox





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC