We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

attachemnt file at gmail not working

myaspnet
myaspnet asked
on
Medium Priority
196 Views
Last Modified: 2012-05-11
look at code plaeae what is the error
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Net;

public partial class send2 : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        string file = Server.MapPath("xml/Xml_student2011.xml");
        sendmail1("nabooln@gmail.com", "nabooln@gmail.com", "subject", "body", file);
    }
    public static bool sendmail1(string sender, string recipient, string subject, string body, string file)
    {
        //Create Mail Message Object with content that you want to send with mail.
        MailMessage myMailMessage = new MailMessage();

        myMailMessage.To.Add(recipient);
        myMailMessage.From = new MailAddress(sender);
        myMailMessage.Subject = subject;
        myMailMessage.Body = body;
        Attachment myAttachment = new Attachment(file);
        myMailMessage.Attachments.Add(myAttachment);
       
        NetworkCredential mailAuthentication = new NetworkCredential("mydrhow@gmail.com", "xxxxx");
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com");


        //Enable SSL
        mailClient.EnableSsl = true;
        mailClient.Port = 587;
        mailClient.Credentials = mailAuthentication;
        try
        {
            mailClient.Send(MyMailMessage);
            return true;
        }
        catch (Exception ex)
        {
            string ex2 = ex.ToString();
            return false;
        }
    }
}

Open in new window

Comment
Watch Question

Author

Commented:
this is error
 mailClient.Send(MyMailMessage);
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
very good
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.