Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Error   1   'MailPriority' is an ambiguous reference between 'System.Web.Mail.MailPriority' and 'System.Net.Mail.MailPriority'  E:\E-mobileshop\admin\customerdetails.aspx.cs   223 112 E:\E-mobileshop\

cod :

protected void SendEmailWithAttachment(object sender, EventArgs e)
{
SendEmail(txtTo.Text.Trim(), "", "", txtSubject.Text.Trim(), txtBody.Text.Trim(), MailPriority.High, false);
}

private void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, MailPriority priority, bool isHtml)
{
try
{
using (SmtpClient smtpClient = new SmtpClient())
{
using (MailMessage message = new MailMessage())
{
MailAddress fromAddress = new MailAddress("ramji.kid@gmail.com", "ramji.kid, gmail.Com");

// You can specify the host name or ipaddress of your server
smtpClient.Host = "smtp.gmail.com"; //you can also specify mail server IP address here

//Default port will be 25
smtpClient.Port = 25;

NetworkCredential info = new NetworkCredential("ramji.kid@gmail.com", "r");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = info;

//From address will be given as a MailAddress Object
message.From = fromAddress;
message.Priority = priority;

// To address collection of MailAddress
message.To.Add(txt_receiver.Text);
message.Subject = txt_subject.Text;
if (ccAddress.Length > 0)
{
message.CC.Add(ccAddress);
}
if (bccAddress.Length > 0)
{
message.Bcc.Add(bccAddress);
}

//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = isHtml;

// Message body content
message.Body = txt_body.Text;

// Add the attachment, if any
if (FileUpload1.PostedFile.ContentLength > 0)
{
Attachment attachment = new Attachment(Path.GetFullPath(FileUpload1.PostedFile.FileName));
message.Attachments.Add(attachment);
}

// Send SMTP mail
smtpClient.Send(message);

lblMessage.Text = "Email sent to " + toAddress + " successfully !";
}
}
}
catch (Exception ee)
{
lblMessage.Text = ee.ToString();
}
}




can u please help me to rectify this error i am waiting for u
Posted
Updated 19-Dec-12 0:32am
v3
Comments
Zafar Sultan 19-Dec-12 6:18am    
Good, the OP specified his gmail's user id as well as password!!!

Hi Please try this code below

C#
private void button1_Click(object sender, RoutedEventArgs e)
        {
 string footer = "If you have any questions about appointment cancelation,please do not hesitate to call your clinic front desk";
            string subject = "Appointment Canceled";
            string body = "Hi" + " " + "google" + "\n\n" + footer;

            MailMessage message = new MailMessage();

            message.From = new MailAddress("Ngqandu.Anele@gmail.com");
            message.To.Add(new MailAddress("Anele.Ngqandu@live.nmmu.ac.za"));//sending to my nmmu live account
            message.Subject = subject;
            message.Body = body;

            SmtpClient client = new SmtpClient();
            client.Credentials = new    System.Net.NetworkCredential("account@gmail.com", "password");

            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }




Vote if it helps...
 
Share this answer
 
Basically, you have two using statements in the same code file which refer to different assemblies:
C#
using System.Web.Mail;

and
C#
using System.Net.Mail;
And both assemblies contain the same name: MailPriority. The system cannot tell which one you mean, so you have two alternatives:
1) Get rid of one of the using statements.
2) Explicitly specify which you mean by prefixing MailPriority by the full reference name.
 
Share this answer
 
Comments
ramjiricky 19-Dec-12 5:07am    
thank's for your reply but now i got the error like this

System.ArgumentException: The path is not of a legal form
OriginalGriff 19-Dec-12 5:11am    
And what was the line you got the error on?
Copy and paste it here!
ramjiricky 19-Dec-12 5:24am    
hi sir,
without attachment the message has been send but if i have attach some file then the error will display like below ...and i am using the same code which one i have mentioned previous question

System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\free-photo-background-952-m.jpg'. File name: 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\free-photo-background-952-m.jpg' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) at System.Net.Mail.AttachmentBase..ctor(String fileName) at System.Net.Mail.Attachment..ctor(String fileName) at customerdetails.SendEmail(String toAddress, String ccAddress, String bccAddress, String subject, String body, MailPriority priority, Boolean isHtml) in e:\E-mobileshop\admin\customerdetails.aspx.cs:line 275
OriginalGriff 19-Dec-12 5:37am    
The error message is pretty explicit:
Could not find file 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\free-photo-background-952-m.jpg'
This normally means the file does not exist...have you checked?
ramjiricky 19-Dec-12 5:49am    
can u please give me a exact code for send a mail with attachment
thank's for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900