doramail05
asked on
MailAddressCollection addresses error on sending mail with system.net.mail
while using system.net.mail to send email in asp.net, had encountered the following error:
System.ArgumentException: The parameter 'addresses' cannot be an empty string. Parameter name: addresses at System.Net.Mail.MailAddres sCollectio n.Add(Stri ng addresses) at SendMail.btnSend_Click(Obj ect sender, EventArgs e)
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(txtRece iver.Text) ;
mailMessage.CC.Add(txtCc.T ext);
mailMessage.Bcc.Add(txtBcc .Text);
mailMessage.From = new MailAddress(txtSender.Text , "asdasda");
// mailMessage.From = txtSender.Text;
// mailMessage.To = txtReceiver.Text;
// mailMessage.Cc = txtCc.Text;
// mailMessage.Bcc = txtBcc.Text;
mailMessage.Subject = txtSubject.Text;
mailMessage.Body = txtBody.Text;
List<string> lststring = new List<string>();
lststring.Add(txtReceiver. Text);
lststring.Add(txtCc.Text);
lststring.Add(txtBcc.Text) ;
MailAddressCollection collection = new MailAddressCollection();
collection.Add(new MailAddress(txtReceiver.Te xt));
not sure whether it will use one address or many addresses, if required many addresses, it may required list collection, but the list collecton could not be enter to collection.Add,
therefore, tried the single address, as stated in other forum, but the error is still there
System.ArgumentException: The parameter 'addresses' cannot be an empty string. Parameter name: addresses at System.Net.Mail.MailAddres
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(txtRece
mailMessage.CC.Add(txtCc.T
mailMessage.Bcc.Add(txtBcc
mailMessage.From = new MailAddress(txtSender.Text
// mailMessage.From = txtSender.Text;
// mailMessage.To = txtReceiver.Text;
// mailMessage.Cc = txtCc.Text;
// mailMessage.Bcc = txtBcc.Text;
mailMessage.Subject = txtSubject.Text;
mailMessage.Body = txtBody.Text;
List<string> lststring = new List<string>();
lststring.Add(txtReceiver.
lststring.Add(txtCc.Text);
lststring.Add(txtBcc.Text)
MailAddressCollection collection = new MailAddressCollection();
collection.Add(new MailAddress(txtReceiver.Te
not sure whether it will use one address or many addresses, if required many addresses, it may required list collection, but the list collecton could not be enter to collection.Add,
therefore, tried the single address, as stated in other forum, but the error is still there
ASKER
previously used 2)
now use 1) after reading forums, for testing
now use 1) after reading forums, for testing
ASKER
source file destinaton :
http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT
Is it reference site or you are pointing to a problem you posted there?
ASKER
no, not sure, but i was working on the source file found that,
ASKER
just that it could not send the attachment but only the email
error :
System.IO.IOException: The process cannot access the file 'C:..\Websites\SendEmailwi thAttachme nt\timeshe et.xlsx' because it is being used by another process.
i guess this works:
eventhough it is checked from the task manager it is not running there,
error :
System.IO.IOException: The process cannot access the file 'C:..\Websites\SendEmailwi
i guess this works:
eventhough it is checked from the task manager it is not running there,
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("asdasda@gmail.com", "pwd"),
};
using (var message = new MailMessage("asdasd@gmail.com", "asddsasa@gmail.com")
{
Subject = "sadsasdaad",
Body = "assadsadsada",
})
{
// string strFileName = null;
if (inpAttachment2.PostedFile != null)
{
HttpPostedFile attFile = inpAttachment2.PostedFile;
int attachFileLength = attFile.ContentLength;
if (attachFileLength > 0)
{
strFileName = Path.GetFileName(inpAttachment2.PostedFile.FileName);
inpAttachment2.PostedFile.SaveAs(Server.MapPath(strFileName));
Attachment attach = new Attachment(Server.MapPath(strFileName));
//MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
message.Attachments.Add(attach);
attach.Dispose();
// attach2 = strFileName;
}
}
smtp.Send(message);
message.Dispose();
You need to remove memory references to close the file first before trying to access it..
Hope this works
inpAttachment2.PostedFile.SaveAs(Server.MapPath(strFileName));
inpAttachment2.PostedFile.FileContent.Dispose();
Attachment attach = new Attachment(Server.MapPath(strFileName));
Hope this works
ASKER
hi there,
notice that there are only, contenttype, contentlength, inputstream, filename, could not really find FileContent
example :
inpAttachment2.PostedFile. InputStrea m.Dispose( );
notice that there are only, contenttype, contentlength, inputstream, filename, could not really find FileContent
example :
inpAttachment2.PostedFile.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
figure out the above code before this causes the problem
1) System.Net.Mail.MailMessag
2) System.Web.Mail.MailMessag