.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Sgraph Infotech
Imran Ghani
Post New Web Links

System.Net.Mail.MailAddress cannot be serialized because it does not have a parameterless constructo

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :.NET Framework
 
Hi all,

In my webservice i have method to send email.

In service.cs file i  have following code.

[

WebMethod(Description = "Common method to send email.")]

 

public void SendEmail(MailMessage mail)

{

 

Dashboard.SendEmail(mail);

}


and in my class.cs i have

<


View Complete Post


More Related Resource Links

Email Help (System.Net.Mail)

  

Hi I have a annoying problem. 
I have created a page which takes users details for a quote.

I have then created the form to be emailed to both the user and myself. (Which works fine ATM)

However I would also like to be able to attach a file containing terms and conditions to the email.

I have tried doing this using 

EmailMsg.Attachments.Add(new Attachment("C:\\attachme.txt"));

But everytime that line of code is hit it fails and is caught by my try catch.

Take that line out and the email sends fine, put it in and it breaks the whole page.

Am I missing something really obvious?


system.net.mail cc issue

  

I have an array of addresses.....

	Protected Function GetData() As String()
Dim stringArr(3) As String

stringArr(0) = "youremail1@fakeaddress.com"
stringArr(1) = "youremail2@fakeaddress.com"
stringArr(2) = "youremail3@fakeaddress.com"

Return stringArr

End Function

I am getting an error when i run the code in the CC part....please put this in the right syntax..

MassMail.CC.Add() .......getdata???



System.Net.Mail HTML Template Problem

  

What do I need here ?????? To make this work??


Dim MassMail As New MailMessage()


        Dim Template As ??????????????


        MassMail.To.Add(New MailAddress(TextBox_massemailto.Text))
        MassMail.From = New MailAddress("You@me.com")

        ' MassMail.CC.Add()
        MassMail.Subject = TextBox_massemailsubject.Text
        MassMail.Body = TextBox_massemailBody.Text
        ' MassMail.Body = Template.BodyFileName = "EmailTemplates/BusinessAdBrochure.htm"
        MassMail.Priority = MailPriority.High

        Dim smtpclient As New SmtpClient("relay-hosting.secureserver.net")
        smtpclient.Credentials = New System.Net.NetworkCredential(""You@me.com"", "pasword")
        smtpclient.Port = 25
        smtpclient.EnableSsl = False
        smtpclien

System.Net.Mail.SmtpException: net_io_connectionclosed

  
I'm getting "System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed." but only occasionally.  I'm confused because:1) The SMTP server is the local machine so why would the connection ever fail? and2) The error only happens sometimesThere was a similar question posted here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=418540&SiteID=1 but it seems they were having problems sending any mail to begin with.Here is the full stack trace:System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)   at System.Net.Mail.SmtpReplyReader.ReadLine()   at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)   at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)   at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)   at System.Net.ClosableStream.Close()   at System.Net.Mail.MailWriter.Close()   at System.Net.Mail.SmtpClient.Send(MailMessage message)I'm unable to recreate this error since it onl

System.Net.Mail.SmtpException was caught

  
i am trying to implement this in my application to send a mail but i keep getting this error i configured in my web.config<system.net>        <mailSettings>            <smtp from="dep-it@public-health.gov.lb" deliveryMethod="Network">                <network host="mail.ogero.gov.lb" password="" userName="" port="25" defaultCredentials="true"/>            </smtp>        </mailSettings>    </system.net>and this is the code i'm using :Public Function SendMail(ByVal strTo As String, ByVal strSubject As String, ByVal strMsg As String, ByVal path As String) As Boolean        'ByVal strFrom As String,        Try            ' Create the mail message            Dim objMailMsg As MailMessage = New MailMessage("dep-it@publichealth.gov.lb", strTo)            objMailMsg.BodyEncoding = Encoding.UTF8 &nbs

Email Encryption using System.Net.Mail assembly

  
Hi folks, Has anyone used the above assemblies to send emails using public key enryption, specifically PGP? Cheers Mark 

I don't have "System.Net.Mail.SmtpPermission" ?

  
My project works well (send e-mail) in local PC, but it can not when uploaded. I have checked SMTP port again and again, port 3535 is open. May the problem caused by config file? I think no. Appreciate all the help, thank you so much and hope to hear from you soon!   Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Source Error: Line 66: SmtpClient client = new SmtpClient(); Line 67: client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD); Line 68: client.Port = 3535; //SMTP_PORT Line 69: client.Host = SMTP_HOST; Line 70: client.EnableSsl = ENABLE_SSL; Source File: d:\hosting\clearpathadmin\contact-us.aspx.cs    Line: 68 Stack Trace: [SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Security.CodeAccessSecurityEngine.Chec

System.Net.Mail e-mail header info problem

  
I'm new to using the system.net.mail class and I'm having trouble with a small program I'm writing.  I use my SendMessage() to send an email public static void SendMessage(string msg)         {             System.IO.File.Copy(mySource + msg, destSource + msg);             MailMessage mail = new MailMessage("from@me.com", "to@you.com, msg, "");                        Attachment attch = new Attachment(destSource + msg, "text/plain; format=flowed;reply-type=original"); //content-type text/plain                                   mail.Attachments.Add(attch);                                  MessagingCenter.client.Send(mail);             mail.Dispose();         } However, the email sent

How do I access the custom headers created with System.Net.Mail?

  
I've created some custom headers for my emails.  I've used a breakpoint to see that they are being added to the collection correctly.  I don't understand how to access these from the email that's generated though.  I'm currently dropping the emails into a pickup directory on my local machine and viewing them with Windows Mail.  I have "view all" headers checked in Windows mail but still don't see them when I open my emails in the pick up directory.Can someone please tell me how to access the headers that I added?  Below is an example of how I did it.  I'm hoping to add things like name, address, phone... etc, and then have them visible in the email.   Is this even the correct use of custom headers? message.Headers.Add("X-Name", txtName.Text);  

Sending a Mail Message to Multiple Addresses Using System.Net.Mail

  
 VWD 2008 Express.  Visual Basic. I use the following routine (XXXXX have replaced sensitive data) to try to send an email message to mutiple email addresses.  It only sends to the first email address in the comma-delimited list.  How can I send the message to multiple email addresses?  Thanks for the help. Protected Sub SendButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendButton.Click 'Send the message to all users who have emails. Dim smtpClient As SmtpClient = New SmtpClient() Dim message As MailMessage = New MailMessage() Dim Success As Boolean, I As Integer, strTO As String = "" Try 'Gather all user email addresses Dim strSQL = "SELECT EMail from aspnet_membership where Email<>''" Dim MyDataset As DataSet = GetDataSet(strSQL, Success) I = 0 For Each dr As DataRow In MyDataset.Tables(0).Rows If I = MyDataset.Tables(0).Rows.Count - 1 Then strTO = strTO + dr("Email") Else strTO = strTO + dr("Email") + "," End If I = I + 1 Next Dim toAddress As New MailAddress(strTO, "To All Users") 'Ga

'System.Net.Mail.SmtpException: Failure sending mail.

  
'System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)   at System.Net.Mail.SmtpReplyReader.ReadLine()   at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)   at System.Net.Mail.SmtpClient.Send(MailMessage message)   --- End of inner exception stack trace ---   at System.Net.Mail.SmtpClient.Send(MailMessage message)   at crmpark.bemail.sendemail(String toemail, String frmemail, String bcc, String cc, String strattach, String Subject, String bmessage) in    getting the above error when sending mail from asp.net 2.0

Sending email System.net.mail

  

Ok here's my problem. I have a contact page with a txtbox for users name, email and message for users to contact me.  When I send the message it goes through, but the senders email is always my email. Even though i have set it to the txtEmail.Text property. So when I reply, it sends me an email. What am I not seeing that I messed up. Also this is running from VS 2005.

                 protected void btnSubmit_Click1(object sender, ImageClickEventArgs e)
                {

                 const string toAddress = "myemail@gmail.com";
 
                    MailAddress from = new MailAddress(txtEmail.Text, txtName.Text);
			        MailAddress to = new MailAddress(toAddress, "Admin");
			        MailMessage message = new MailMessage(from, to);

			        // set properties
			        message.Subject = txtName.Text + " has sent you an email!";
			        message.Body = txtMessage.Text;
                                message.IsBodyHtml = false;

			        //create smtp object
			        SmtpClient client = new SmtpClient();
                               client.EnableSsl = true;
  
                    try
                    {
                        client.Send(message);
                    }

                    catch(Exception ex)
 

'System.Net.Mail.SmtpException- any solution for the same

  

'System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)   at System.Net.Mail.SmtpReplyReader.ReadLine()   at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)   at System.Net.Mail.SmtpClient.Send(MailMessage message)   --- End of inner exception stack trace ---   at System.Net.Mail.SmtpClient.Send(MailMessage message) 

 i tried many things but still awaiting solution


Error while sending email using ASP.NET 2.0 -'System.Net.Mail.SmtpException: Failure sending mail

  

'System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)   at System.Net.Mail.SmtpReplyReader.ReadLine()   at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)   at System.Net.Mail.SmtpClient.Send(MailMessage message)   --- End of inner exception stack trace ---   at System.Net.Mail.SmtpClient.Send(MailMessage message) 

 i tried many things but still awaiting solution


svk

 

sometimes  i get this error

 'System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.mail.y

Embedding hyperlink in email using System.Net.Mail;

  

My goal is to embed a link in the email.

Purpose is that the user needs to click the link in his email to activate the account.

But my emailbody with the link is just shown as plain-Non clickabel text.

the body text looks like:

string mailBody = "please click the following link to activate your account:<br>

string mailBody = "please click the following link to activate your account:<br>" +
                          "http://www.website.com?activate=.....";
                         
I use the follwing code
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText.Replace("\n","<BR>"), null  , System.Net.Mime.MediaTypeNames.Text.Html);
mailMsg.AlternateViews.Add(plainView);
mailMsg.AlternateViews.Add(htmlView);

smtp.Send(mailMsg);

How do i embed this link in the receivers ema

System.Net.Mail Header issue

  

I am trying to send additional info from a form via the Headers property of mail.  When I run the below code, the email is sent along with the From, To, Subject and Bosy values, but nothing else.  How do I add the values listed?

 

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim mm As New MailMessage()

mm.From = New MailAddress(txtEmail.text)

mm.To.Add(New MailAddress("example@yahoo.com"))

'(2) Assign the MailMessage's properties

mm.Subject = "Get A Quote"

mm.Body = "This is a test."

mm.Headers.Add ("X-ContractorName",txtContractor.text)

mm.Headers.Add ("X-FirstName",txtFirstName.text)

mm.Headers.Add ("X-LastName",txtLastName.text)

mm.Headers.Add ("X-Address",txtAddress.text)

mm.Headers.Add ("X-City",txtCity.text)

mm.Headers.Add ("X-State",txtState.text)

mm.Headers.Add ("X-Zip",txtZip.text)

mm.Headers.Add ("X-MainPhone",txtMainPhone.text)

mm.Headers.Add ("X-AlternatePhone",txtAlternatePhone.text)

mm.Headers.Add ("X-Email",txtEmail.text)

mm.Headers.Add ("X-ContainerSize",containerSize.text)

mm.Headers.Add ("X-ContainerContentOther",text

System.Net.Mail ignores Sender address when delivery method is SpecifiedPickupDirectory

  

Has anybody else had an issue with the sender address not being used as the return-path/bounce address when using system.net.mail to send email with a different address for the return-path/sender and the from address and using the SpecifiedPickupDirectory delivery method? This issue is particularly important when you need to send mail from a "user" address, but want bounce backs to come to a different address so they can be processed.

Using the code below, I think you can reproduce the issue.


Imports System.Net.Mail
Partial Class emailtest
    Inherits System.Web.UI.Page

  Protected Sub test_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles test.Click

    ' Build Message
    Dim mail As New MailMessage
    mail.To.Add("user@gmail.com")
    mail.From = New MailAddress("from@domain.com")
    mail.Sender = New MailAddress("sender@domain.com")
    mail.Subject = "Test Subject"
    mail.Body = "Test Body"

    ' Drop in Pickup Directory
    Dim smtpPK As New SmtpClient
    smtpPK.DeliveryMethod = SmtpDeliveryMethod.Sp

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend