|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Hi,
I want to have a function where the user can enter an email address and then send email with a selected file as an attachment. Can you show me any walkthroughs or document where this is done? -- Thanks Morris Do you know how to send an email in ASP.NET at all, or is it only the
attaching a file that you need help with? The two main classes you will need to deal with are: System.Net.Mail.SmtpClient System.Net.Mail.MailMessage All you need to do with the SmtpClient is pass it a String in the constructor specifying the SMTP server. Most of the properties of MailMessage should be pretty self-explanatory. To add a file to the MailMessage as an attachment, use the Add method of the Attachments property. Once you have set all the desired properties of the MailMessage, use a statement similar to the following to send it: yoursmtp.Send(yourmailmsg) Hopefully this helps! Show quoteHide quote "Morris Neuman" <Morris@online.nospam> wrote in message news:9F1FD305-535E-4B57-890F-760D7AF8F926@microsoft.com... > Hi, > > I want to have a function where the user can enter an email address and > then > send email with a selected file as an attachment. > > Can you show me any walkthroughs or document where this is done? > -- > Thanks > Morris Hi Morris,
As for sending email in ASP.NET web page(with attachment), I think you need to implement such a web page via the following approach: ** Your page will need some FileUpload controls to let user first add some attachments. These operation will post back to server so as to save all the attachments to a temp folder on server(for later email sending use). For ASP.NET file uploading, you can refer to the below article: #File Upload with ASP.NET http://www.codeproject.com/KB/aspnet/fileupload.aspx ** After you've file uploading functionality on page, you can add code to send email. In .net 2.0, you can use Sysetem.Net.Mail classes to send email(also support add attachments). There are many samples here for your reference: #Sending Email with System.Net.Mail http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx http://aspnet.4guysfromrolla.com/articles/072606-1.aspx And I've also found a code project article which combine the above two parts. I think it is quite close to what you want. #ASP.NET email with multiple attachments http://www.codeproject.com/KB/aspnet/ASPNETwebmail.aspx Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications. Note: MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 2 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- Show quoteHide quote >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> >Subject: Email >Date: Thu, 15 Jan 2009 20:23:01 -0800 >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols > >Hi, > >I want to have a function where the user can enter an email address and then >send email with a selected file as an attachment. > >Can you show me any walkthroughs or document where this is done? >-- >Thanks >Morris > Thanks. Got the basics of the email working.
One question: Is there a way the user enter several email addresses in textbox1, each address seperated by a semicolon, set EmailTo = textbox1.Text and then add entire string to message.To.Add(new MailAddress(EmailTo1))? I get error doing this and have to parse the textbox1.Text string and do an message.To.Add(new...) for each address. -- Show quoteHide quoteThanks Morris ""Steven Cheng"" wrote: > Hi Morris, > > As for sending email in ASP.NET web page(with attachment), I think you need > to implement such a web page via the following approach: > > ** Your page will need some FileUpload controls to let user first add some > attachments. These operation will post back to server so as to save all the > attachments to a temp folder on server(for later email sending use). For > ASP.NET file uploading, you can refer to the below article: > > #File Upload with ASP.NET > http://www.codeproject.com/KB/aspnet/fileupload.aspx > > ** After you've file uploading functionality on page, you can add code to > send email. In .net 2.0, you can use Sysetem.Net.Mail classes to send > email(also support add attachments). There are many samples here for your > reference: > > #Sending Email with System.Net.Mail > http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx > > http://aspnet.4guysfromrolla.com/articles/072606-1.aspx > > > > And I've also found a code project article which combine the above two > parts. I think it is quite close to what you want. > > #ASP.NET email with multiple attachments > http://www.codeproject.com/KB/aspnet/ASPNETwebmail.aspx > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msd***@microsoft.com. > > ================================================== > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications. > > Note: MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 2 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions. Issues of this > nature are best handled working with a dedicated Microsoft Support Engineer > by contacting Microsoft Customer Support Services (CSS) at > http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. > > > > -------------------- > >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> > >Subject: Email > >Date: Thu, 15 Jan 2009 20:23:01 -0800 > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols > > > >Hi, > > > >I want to have a function where the user can enter an email address and > then > >send email with a selected file as an attachment. > > > >Can you show me any walkthroughs or document where this is done? > >-- > >Thanks > >Morris > > > > If you separate the addresses by a comma rather than a semicolon you can
simply do the following: message.To.Add(textbox1.Text) If the addresses are separated by a semicolon, you can simply modify this statement by using the String.Replace() method as follows: message.To.Add(textbox1.Text.Replace(";",",")) There is no need to manually parse the addresses (although this wouldn't be that hard using the String.Split() method and a simple loop). Hopefully this helps. Show quoteHide quote "Morris Neuman" <Morris@online.nospam> wrote in message news:96B942E7-9345-4FDA-AF3E-84CFD9CDB68F@microsoft.com... > Thanks. Got the basics of the email working. > > One question: > Is there a way the user enter several email addresses in textbox1, each > address seperated by a semicolon, set EmailTo = textbox1.Text and then add > entire string to message.To.Add(new MailAddress(EmailTo1))? > > I get error doing this and have to parse the textbox1.Text string and do > an > message.To.Add(new...) for each address. > -- > Thanks > Morris > > > ""Steven Cheng"" wrote: > >> Hi Morris, >> >> As for sending email in ASP.NET web page(with attachment), I think you >> need >> to implement such a web page via the following approach: >> >> ** Your page will need some FileUpload controls to let user first add >> some >> attachments. These operation will post back to server so as to save all >> the >> attachments to a temp folder on server(for later email sending use). For >> ASP.NET file uploading, you can refer to the below article: >> >> #File Upload with ASP.NET >> http://www.codeproject.com/KB/aspnet/fileupload.aspx >> >> ** After you've file uploading functionality on page, you can add code to >> send email. In .net 2.0, you can use Sysetem.Net.Mail classes to send >> email(also support add attachments). There are many samples here for your >> reference: >> >> #Sending Email with System.Net.Mail >> http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx >> >> http://aspnet.4guysfromrolla.com/articles/072606-1.aspx >> >> >> >> And I've also found a code project article which combine the above two >> parts. I think it is quite close to what you want. >> >> #ASP.NET email with multiple attachments >> http://www.codeproject.com/KB/aspnet/ASPNETwebmail.aspx >> >> Sincerely, >> >> Steven Cheng >> >> Microsoft MSDN Online Support Lead >> >> >> Delighting our customers is our #1 priority. We welcome your comments and >> suggestions about how we can improve the support we provide to you. >> Please >> feel free to let my manager know what you think of the level of service >> provided. You can send feedback directly to my manager at: >> msd***@microsoft.com. >> >> ================================================== >> Get notification to my posts through email? Please refer to >> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications. >> >> Note: MSDN Managed Newsgroup support offering is for non-urgent issues >> where an initial response from the community or a Microsoft Support >> Engineer within 2 business day is acceptable. Please note that each >> follow >> up response may take approximately 2 business days as the support >> professional working with you may need further investigation to reach the >> most efficient resolution. The offering is not appropriate for situations >> that require urgent, real-time or phone-based interactions. Issues of >> this >> nature are best handled working with a dedicated Microsoft Support >> Engineer >> by contacting Microsoft Customer Support Services (CSS) at >> http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx >> ================================================== >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> >> >> >> -------------------- >> >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> >> >Subject: Email >> >Date: Thu, 15 Jan 2009 20:23:01 -0800 >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols >> > >> >Hi, >> > >> >I want to have a function where the user can enter an email address and >> then >> >send email with a selected file as an attachment. >> > >> >Can you show me any walkthroughs or document where this is done? >> >-- >> >Thanks >> >Morris >> > >> >> Thanks for Nathan's input.
Nice solution. By using the Replace method, we can avoid parsing the multi address (via split) and join them again with the new separator. Regards, Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. -------------------- >From: "Nathan Sokalski" <njsokal***@hotmail.com> <2c4V#C7dJHA.4***@TK2MSFTNGHUB02.phx.gbl> >References: <9F1FD305-535E-4B57-890F-760D7AF8F***@microsoft.com> <96B942E7-9345-4FDA-AF3E-84CFD9CDB***@microsoft.com> Show quoteHide quote >Subject: Re: Email >Date: Sun, 18 Jan 2009 19:27:16 -0500 > >If you separate the addresses by a comma rather than a semicolon you can >simply do the following: > >message.To.Add(textbox1.Text) > >If the addresses are separated by a semicolon, you can simply modify this >statement by using the String.Replace() method as follows: > >message.To.Add(textbox1.Text.Replace(";",",")) > >There is no need to manually parse the addresses (although this wouldn't be >that hard using the String.Split() method and a simple loop). Hopefully this >helps. >-- >Nathan Sokalski >njsokal***@hotmail.com >http://www.nathansokalski.com/ > >"Morris Neuman" <Morris@online.nospam> wrote in message >news:96B942E7-9345-4FDA-AF3E-84CFD9CDB68F@microsoft.com... >> Thanks. Got the basics of the email working. >> >> One question: > Thanks for the response. I tried your suggestion and entered in multiple
email addresses followed by comma, I even tried with and with a space after the comma. However in both cases, the first recipient receives the email but the second one does not. In debugging I do see that Textbox1.Text = "sa***@speechsoft.com, webmas***@speechsoft.com", and the message To Count =1 showing just the first email address. When the first recipient gets the message, the to address in the email received only has the 1 email address. Is there something else I have to do to allow user to input multiple email address and the send to all in the input list? -- Show quoteHide quoteThanks for your help. Morris ""Steven Cheng"" wrote: > Thanks for Nathan's input. > > Nice solution. By using the Replace method, we can avoid parsing the multi > address (via split) and join them again with the new separator. > > Regards, > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msd***@microsoft.com. > > > > -------------------- > >From: "Nathan Sokalski" <njsokal***@hotmail.com> > >References: <9F1FD305-535E-4B57-890F-760D7AF8F***@microsoft.com> > <2c4V#C7dJHA.4***@TK2MSFTNGHUB02.phx.gbl> > <96B942E7-9345-4FDA-AF3E-84CFD9CDB***@microsoft.com> > >Subject: Re: Email > >Date: Sun, 18 Jan 2009 19:27:16 -0500 > > > > >If you separate the addresses by a comma rather than a semicolon you can > >simply do the following: > > > >message.To.Add(textbox1.Text) > > > >If the addresses are separated by a semicolon, you can simply modify this > >statement by using the String.Replace() method as follows: > > > >message.To.Add(textbox1.Text.Replace(";",",")) > > > >There is no need to manually parse the addresses (although this wouldn't > be > >that hard using the String.Split() method and a simple loop). Hopefully > this > >helps. > >-- > >Nathan Sokalski > >njsokal***@hotmail.com > >http://www.nathansokalski.com/ > > > >"Morris Neuman" <Morris@online.nospam> wrote in message > >news:96B942E7-9345-4FDA-AF3E-84CFD9CDB68F@microsoft.com... > >> Thanks. Got the basics of the email working. > >> > >> One question: > > > > Thanks for your reply Morris,
Then, I think we'd better still use the stereotype code to add multiple receivers: ============================= public static void SendMail() { string receivers = "receiv***@test.org;receiv***@test.org;receiv***@test.org"; MailMessage msg = new MailMessage(); msg.From = new MailAddress("sen***@test.org"); foreach (string rec in receivers.Split(';')) { msg.To.Add(rec); } msg.Subject = "This is just a test message!"; msg.Body = "Sorry for the inconvenience."; SmtpClient client = new SmtpClient("smtphost"); client.UseDefaultCredentials = true; client.Send(msg); } ============================== http://www.systemnetmail.com/faq/3.2.3.aspx Hope this helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. -------------------- Show quoteHide quote >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> >Subject: Re: Email >Date: Mon, 19 Jan 2009 06:37:06 -0800 >Thanks for the response. I tried your suggestion and entered in multiple >email addresses followed by comma, I even tried with and with a space after >the comma. >However in both cases, the first recipient receives the email but the second >one does not. >In debugging I do see that Textbox1.Text = "sa***@speechsoft.com, >webmas***@speechsoft.com", and the message To Count =1 showing just the first >email address. > >When the first recipient gets the message, the to address in the email >received only has the 1 email address. > >Is there something else I have to do to allow user to input multiple email >address and the send to all in the input list? >-- >Thanks for your help. >Morris > > >"" Great this worked. Thanks.
-- Show quoteHide quoteThanks Morris ""Steven Cheng"" wrote: > Thanks for your reply Morris, > > Then, I think we'd better still use the stereotype code to add multiple > receivers: > > ============================= > public static void SendMail() > { > string receivers = > "receiv***@test.org;receiv***@test.org;receiv***@test.org"; > > MailMessage msg = new MailMessage(); > msg.From = new MailAddress("sen***@test.org"); > > foreach (string rec in receivers.Split(';')) > { > msg.To.Add(rec); > } > > msg.Subject = "This is just a test message!"; > msg.Body = "Sorry for the inconvenience."; > > SmtpClient client = new SmtpClient("smtphost"); > client.UseDefaultCredentials = true; > client.Send(msg); > } > ============================== > > http://www.systemnetmail.com/faq/3.2.3.aspx > > Hope this helps. > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msd***@microsoft.com. > > > -------------------- > >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> > >Subject: Re: Email > >Date: Mon, 19 Jan 2009 06:37:06 -0800 > > >Thanks for the response. I tried your suggestion and entered in multiple > >email addresses followed by comma, I even tried with and with a space > after > >the comma. > >However in both cases, the first recipient receives the email but the > second > >one does not. > >In debugging I do see that Textbox1.Text = "sa***@speechsoft.com, > >webmas***@speechsoft.com", and the message To Count =1 showing just the > first > >email address. > > > >When the first recipient gets the message, the to address in the email > >received only has the 1 email address. > > > >Is there something else I have to do to allow user to input multiple email > >address and the send to all in the input list? > >-- > >Thanks for your help. > >Morris > > > > > >"" > > You're welcome Morris,
If there is anything else we can help, please feel free to post here. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. -------------------- Show quoteHide quote >From: =?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= <Morris@online.nospam> >Subject: Re: Email >Date: Tue, 20 Jan 2009 07:52:03 -0800 > >Great this worked. Thanks. > >-- >Thanks >Morris > > >""Steven Cheng"" wrote: > >> Thanks for your reply Morris, >> >> Then, I think we'd better still use the stereotype code to add multiple >> receivers: >> >> ============================= >> public static void SendMail() >> { >> string receivers = >> "receiv***@test.org;receiv***@test.org;receiv***@test.org"; >> >> MailMessage msg = new MailMessage(); >> msg.From = new MailAddress("sen***@test.org"); >> >> foreach (string rec in receivers.Split(';')) >> { >> msg.To.Add(rec); >> } >> >> msg.Subject = "This is just a test message!"; >> msg.Body = "Sorry for the inconvenience."; >> >>
Other interesting topics
Dropdownlist datasource dependency
Check for table Adapting ReorderList WebControl for rendering dynamic html Need help for solution in ASP.NET with VB OnClientClick with confirm doesn't work Re: FTP download Panels and dynamic controls...again Validator for checkbox is not getting triggered always RE: SelectCommand with SelectParameters.Add Re: Databinding Syntax Not Working in ListView LayoutTemplate |
|||||||||||||||||||||||