|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Attaching multiple files of any type to a mail message?I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav files) or images (bmp, gif or tiff) I can send the email messages OK but the attachments are giving me grief. Can anyone provide some code that adds attachments to web mail messages. Thanks for any help, Bob Robert,
It depends how you sent the email. If you use the default client method, you cannot use attachment. If you use SMTP (only on "professional and 2003 OS") than you can use SMTP mail. So let us know what you are doing? Cor Show quoteHide quote "Robert Dufour" <bduf***@sgiims.com> schreef in bericht news:eyRYIDyEHHA.4280@TK2MSFTNGP04.phx.gbl... >I am trying to use framework 1.1 - stuck with it. to send emails from a >windows form application. The email messages can have attachments, usually >two and they can be either text or sounds (wav files) or images (bmp, gif >or tiff) > > I can send the email messages OK but the attachments are giving me grief. > > Can anyone provide some code that adds attachments to web mail messages. > > Thanks for any help, > Bob > > > Cor this is the snippet of code that I use so far,
Imports System.Web.Mail Public Class clsWebMail Public Sub SendWebMail(ByVal Mailto As String, _ ByVal MailFrom As String, _ ByVal Subject As String, _ ByVal Body As String, _ Optional ByVal MailAttachments As String = "", _ Optional ByVal MailCC As String = "", _ Optional ByVal MailBcc As String = "", _ Optional ByVal ServerName As String = "localhost", _ Optional ByVal UserLogin As String = "", _ Optional ByVal Password As String = "") 'The mail attachments string should contain semi colon delimited full pathnames 'of the files to be attached. Try Dim mailMsg As New MailMessage With mailMsg ..From = MailFrom ..To = Mailto ..Cc = MailCC ..Bcc = MailBcc ..Subject = Subject ..Body = Body ..Priority = MailPriority.High End With Dim AttachItem As String If MailAttachments <> "" Then Dim delimStr As String = ";" Dim delimiter As Char() = delimStr.ToCharArray() Dim split As String() = Nothing split = MailAttachments.Split(delimiter) For Each AttachItem In split Dim attachment As New MailAttachment(AttachItem) 'create the attachment for the message mailMsg.Attachments.Add(attachment) 'add the attachment Next AttachItem End If If ServerName <> "localhost" Then mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserLogin) 'Login name mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Password") 'set your password here End If SmtpMail.SmtpServer = ServerName SmtpMail.Send(mailMsg) Catch ex As Exception WriteLogEntry("Application", "WebMailing", "Web mail send error " & ex.InnerException.Message, EventLogEntryType.Error, 0, 0) End Try End Sub End Class The code works OK except when I try to use the attachments. The project needs to work on a Windows XP Pro or Windows 2000 workstation, it is not intended for a 2003 server. I know that in 2005 the mailing has been moved to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses system.web.mail. I found some info and code samples at http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work and I need it, badly. Bob Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%236HnFr2EHHA.4212@TK2MSFTNGP04.phx.gbl... > Robert, > > It depends how you sent the email. If you use the default client method, > you cannot use attachment. > If you use SMTP (only on "professional and 2003 OS") than you can use SMTP > mail. > > So let us know what you are doing? > > Cor > > "Robert Dufour" <bduf***@sgiims.com> schreef in bericht > news:eyRYIDyEHHA.4280@TK2MSFTNGP04.phx.gbl... >>I am trying to use framework 1.1 - stuck with it. to send emails from a >>windows form application. The email messages can have attachments, usually >>two and they can be either text or sounds (wav files) or images (bmp, gif >>or tiff) >> >> I can send the email messages OK but the attachments are giving me grief. >> >> Can anyone provide some code that adds attachments to web mail messages. >> >> Thanks for any help, >> Bob >> >> >> > > Robert,
The first thing I thought on was "Is Robert using HTML post, because that preservers the charachters" Almost nobody likes that but as you have to do that, than you have no alternatives. At the moment I don't have the time to check your code but this is the best website with information about your problem. If nobody else is checking your code and you keeps the problem, than please reply I can than see if I have the time to check it in the weekend. http://www.systemwebmail.net/ Cor .. Show quoteHide quote "Robert Dufour" <bduf***@sgiims.com> schreef in bericht news:ugjFT1$EHHA.3932@TK2MSFTNGP02.phx.gbl... > Cor this is the snippet of code that I use so far, > Imports System.Web.Mail > > Public Class clsWebMail > > Public Sub SendWebMail(ByVal Mailto As String, _ > > ByVal MailFrom As String, _ > > ByVal Subject As String, _ > > ByVal Body As String, _ > > Optional ByVal MailAttachments As String = "", _ > > Optional ByVal MailCC As String = "", _ > > Optional ByVal MailBcc As String = "", _ > > Optional ByVal ServerName As String = "localhost", _ > > Optional ByVal UserLogin As String = "", _ > > Optional ByVal Password As String = "") > > 'The mail attachments string should contain semi colon delimited full > pathnames > > 'of the files to be attached. > > Try > > Dim mailMsg As New MailMessage > > With mailMsg > > .From = MailFrom > > .To = Mailto > > .Cc = MailCC > > .Bcc = MailBcc > > .Subject = Subject > > .Body = Body > > .Priority = MailPriority.High > > End With > > Dim AttachItem As String > > If MailAttachments <> "" Then > > Dim delimStr As String = ";" > > Dim delimiter As Char() = delimStr.ToCharArray() > > Dim split As String() = Nothing > > split = MailAttachments.Split(delimiter) > > For Each AttachItem In split > > Dim attachment As New MailAttachment(AttachItem) 'create the attachment > for the message > > mailMsg.Attachments.Add(attachment) 'add the attachment > > Next AttachItem > > End If > > If ServerName <> "localhost" Then > > mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", > "1") 'basic authentication > > mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", > UserLogin) 'Login name > > mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", > "Password") 'set your password here > > End If > > SmtpMail.SmtpServer = ServerName > > SmtpMail.Send(mailMsg) > > Catch ex As Exception > > WriteLogEntry("Application", "WebMailing", "Web mail send error " & > ex.InnerException.Message, EventLogEntryType.Error, 0, 0) > > End Try > > End Sub > > End Class > > The code works OK except when I try to use the attachments. The project > needs to work on a Windows XP Pro or Windows 2000 workstation, it is not > intended for a 2003 server. I know that in 2005 the mailing has been moved > to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses > system.web.mail. > I found some info and code samples at > http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work > and I need it, badly. > > Bob > > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message > news:%236HnFr2EHHA.4212@TK2MSFTNGP04.phx.gbl... >> Robert, >> >> It depends how you sent the email. If you use the default client method, >> you cannot use attachment. >> If you use SMTP (only on "professional and 2003 OS") than you can use >> SMTP mail. >> >> So let us know what you are doing? >> >> Cor >> >> "Robert Dufour" <bduf***@sgiims.com> schreef in bericht >> news:eyRYIDyEHHA.4280@TK2MSFTNGP04.phx.gbl... >>>I am trying to use framework 1.1 - stuck with it. to send emails from a >>>windows form application. The email messages can have attachments, >>>usually two and they can be either text or sounds (wav files) or images >>>(bmp, gif or tiff) >>> >>> I can send the email messages OK but the attachments are giving me >>> grief. >>> >>> Can anyone provide some code that adds attachments to web mail messages. >>> >>> Thanks for any help, >>> Bob >>> >>> >>> >> >> > > Cor
I looked at that site and that's where I picked up on how to do it. I did some more testing with my code and I found that the attachments work OK when I use localhost (i.e the built-in SMTP server that gets installed with IIS). But I find that if I try to use an outside mail server like mail.mycompany.com which is outside my LAN and requires a logon user name and password, then I can't send mail messages to which I try to attach files using my code, however if I don't try to use attachments the mail message gets sent OK. It seems to mean that somehow one needs to do some other code when trying to make attachments to a remote server. I could not find any documentation or sample code on that specific problem. Regards, Bob Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:OVJjq1DFHHA.3540@TK2MSFTNGP02.phx.gbl... > Robert, > > The first thing I thought on was "Is Robert using HTML post, because that > preservers the charachters" > Almost nobody likes that but as you have to do that, than you have no > alternatives. > > At the moment I don't have the time to check your code but this is the > best website with information about your problem. If nobody else is > checking your code and you keeps the problem, than please reply I can than > see if I have the time to check it in the weekend. > > http://www.systemwebmail.net/ > > Cor > . > > > > > "Robert Dufour" <bduf***@sgiims.com> schreef in bericht > news:ugjFT1$EHHA.3932@TK2MSFTNGP02.phx.gbl... >> Cor this is the snippet of code that I use so far, >> Imports System.Web.Mail >> >> Public Class clsWebMail >> >> Public Sub SendWebMail(ByVal Mailto As String, _ >> >> ByVal MailFrom As String, _ >> >> ByVal Subject As String, _ >> >> ByVal Body As String, _ >> >> Optional ByVal MailAttachments As String = "", _ >> >> Optional ByVal MailCC As String = "", _ >> >> Optional ByVal MailBcc As String = "", _ >> >> Optional ByVal ServerName As String = "localhost", _ >> >> Optional ByVal UserLogin As String = "", _ >> >> Optional ByVal Password As String = "") >> >> 'The mail attachments string should contain semi colon delimited full >> pathnames >> >> 'of the files to be attached. >> >> Try >> >> Dim mailMsg As New MailMessage >> >> With mailMsg >> >> .From = MailFrom >> >> .To = Mailto >> >> .Cc = MailCC >> >> .Bcc = MailBcc >> >> .Subject = Subject >> >> .Body = Body >> >> .Priority = MailPriority.High >> >> End With >> >> Dim AttachItem As String >> >> If MailAttachments <> "" Then >> >> Dim delimStr As String = ";" >> >> Dim delimiter As Char() = delimStr.ToCharArray() >> >> Dim split As String() = Nothing >> >> split = MailAttachments.Split(delimiter) >> >> For Each AttachItem In split >> >> Dim attachment As New MailAttachment(AttachItem) 'create the attachment >> for the message >> >> mailMsg.Attachments.Add(attachment) 'add the attachment >> >> Next AttachItem >> >> End If >> >> If ServerName <> "localhost" Then >> >> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", >> "1") 'basic authentication >> >> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", >> UserLogin) 'Login name >> >> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", >> "Password") 'set your password here >> >> End If >> >> SmtpMail.SmtpServer = ServerName >> >> SmtpMail.Send(mailMsg) >> >> Catch ex As Exception >> >> WriteLogEntry("Application", "WebMailing", "Web mail send error " & >> ex.InnerException.Message, EventLogEntryType.Error, 0, 0) >> >> End Try >> >> End Sub >> >> End Class >> >> The code works OK except when I try to use the attachments. The project >> needs to work on a Windows XP Pro or Windows 2000 workstation, it is not >> intended for a 2003 server. I know that in 2005 the mailing has been >> moved to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses >> system.web.mail. >> I found some info and code samples at >> http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work >> and I need it, badly. >> >> Bob >> >> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message >> news:%236HnFr2EHHA.4212@TK2MSFTNGP04.phx.gbl... >>> Robert, >>> >>> It depends how you sent the email. If you use the default client method, >>> you cannot use attachment. >>> If you use SMTP (only on "professional and 2003 OS") than you can use >>> SMTP mail. >>> >>> So let us know what you are doing? >>> >>> Cor >>> >>> "Robert Dufour" <bduf***@sgiims.com> schreef in bericht >>> news:eyRYIDyEHHA.4280@TK2MSFTNGP04.phx.gbl... >>>>I am trying to use framework 1.1 - stuck with it. to send emails from a >>>>windows form application. The email messages can have attachments, >>>>usually two and they can be either text or sounds (wav files) or images >>>>(bmp, gif or tiff) >>>> >>>> I can send the email messages OK but the attachments are giving me >>>> grief. >>>> >>>> Can anyone provide some code that adds attachments to web mail >>>> messages. >>>> >>>> Thanks for any help, >>>> Bob >>>> >>>> >>>> >>> >>> >> >> > > Bob,
That sounds very strange to me and looks just like a firewall or virusscanner problem, as there are often in this situations. Cor Show quoteHide quote "Robert Dufour" <bduf***@sgiims.com> schreef in bericht news:OS7OCRXFHHA.2468@TK2MSFTNGP06.phx.gbl... > Cor > I looked at that site and that's where I picked up on how to do it. I did > some more testing with my code and I found that the attachments work OK > when I use localhost (i.e the built-in SMTP server that gets installed > with IIS). But I find that if I try to use an outside mail server like > mail.mycompany.com which is outside my LAN and requires a logon user name > and password, then I can't send mail messages to which I try to attach > files using my code, however if I don't try to use attachments the mail > message gets sent OK. It seems to mean that somehow one needs to do some > other code when trying to make attachments to a remote server. I could not > find any documentation or sample code on that specific problem. > > Regards, > Bob > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message > news:OVJjq1DFHHA.3540@TK2MSFTNGP02.phx.gbl... >> Robert, >> >> The first thing I thought on was "Is Robert using HTML post, because that >> preservers the charachters" >> Almost nobody likes that but as you have to do that, than you have no >> alternatives. >> >> At the moment I don't have the time to check your code but this is the >> best website with information about your problem. If nobody else is >> checking your code and you keeps the problem, than please reply I can >> than see if I have the time to check it in the weekend. >> >> http://www.systemwebmail.net/ >> >> Cor >> . >> >> >> >> >> "Robert Dufour" <bduf***@sgiims.com> schreef in bericht >> news:ugjFT1$EHHA.3932@TK2MSFTNGP02.phx.gbl... >>> Cor this is the snippet of code that I use so far, >>> Imports System.Web.Mail >>> >>> Public Class clsWebMail >>> >>> Public Sub SendWebMail(ByVal Mailto As String, _ >>> >>> ByVal MailFrom As String, _ >>> >>> ByVal Subject As String, _ >>> >>> ByVal Body As String, _ >>> >>> Optional ByVal MailAttachments As String = "", _ >>> >>> Optional ByVal MailCC As String = "", _ >>> >>> Optional ByVal MailBcc As String = "", _ >>> >>> Optional ByVal ServerName As String = "localhost", _ >>> >>> Optional ByVal UserLogin As String = "", _ >>> >>> Optional ByVal Password As String = "") >>> >>> 'The mail attachments string should contain semi colon delimited full >>> pathnames >>> >>> 'of the files to be attached. >>> >>> Try >>> >>> Dim mailMsg As New MailMessage >>> >>> With mailMsg >>> >>> .From = MailFrom >>> >>> .To = Mailto >>> >>> .Cc = MailCC >>> >>> .Bcc = MailBcc >>> >>> .Subject = Subject >>> >>> .Body = Body >>> >>> .Priority = MailPriority.High >>> >>> End With >>> >>> Dim AttachItem As String >>> >>> If MailAttachments <> "" Then >>> >>> Dim delimStr As String = ";" >>> >>> Dim delimiter As Char() = delimStr.ToCharArray() >>> >>> Dim split As String() = Nothing >>> >>> split = MailAttachments.Split(delimiter) >>> >>> For Each AttachItem In split >>> >>> Dim attachment As New MailAttachment(AttachItem) 'create the attachment >>> for the message >>> >>> mailMsg.Attachments.Add(attachment) 'add the attachment >>> >>> Next AttachItem >>> >>> End If >>> >>> If ServerName <> "localhost" Then >>> >>> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", >>> "1") 'basic authentication >>> >>> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", >>> UserLogin) 'Login name >>> >>> mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", >>> "Password") 'set your password here >>> >>> End If >>> >>> SmtpMail.SmtpServer = ServerName >>> >>> SmtpMail.Send(mailMsg) >>> >>> Catch ex As Exception >>> >>> WriteLogEntry("Application", "WebMailing", "Web mail send error " & >>> ex.InnerException.Message, EventLogEntryType.Error, 0, 0) >>> >>> End Try >>> >>> End Sub >>> >>> End Class >>> >>> The code works OK except when I try to use the attachments. The project >>> needs to work on a Windows XP Pro or Windows 2000 workstation, it is not >>> intended for a 2003 server. I know that in 2005 the mailing has been >>> moved to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses >>> system.web.mail. >>> I found some info and code samples at >>> http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work >>> and I need it, badly. >>> >>> Bob >>> >>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message >>> news:%236HnFr2EHHA.4212@TK2MSFTNGP04.phx.gbl... >>>> Robert, >>>> >>>> It depends how you sent the email. If you use the default client >>>> method, you cannot use attachment. >>>> If you use SMTP (only on "professional and 2003 OS") than you can use >>>> SMTP mail. >>>> >>>> So let us know what you are doing? >>>> >>>> Cor >>>> >>>> "Robert Dufour" <bduf***@sgiims.com> schreef in bericht >>>> news:eyRYIDyEHHA.4280@TK2MSFTNGP04.phx.gbl... >>>>>I am trying to use framework 1.1 - stuck with it. to send emails from a >>>>>windows form application. The email messages can have attachments, >>>>>usually two and they can be either text or sounds (wav files) or images >>>>>(bmp, gif or tiff) >>>>> >>>>> I can send the email messages OK but the attachments are giving me >>>>> grief. >>>>> >>>>> Can anyone provide some code that adds attachments to web mail >>>>> messages. >>>>> >>>>> Thanks for any help, >>>>> Bob >>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > |
|||||||||||||||||||||||