 |
|
 |
;PThere you go, enjoy
=============================================
plzz refer this code, u will get ur answer......
using System.Net.Mail;
public static void SendMailMessage(string sMailBody, string sFromAddress, string sFromName,
string[] sToAddress, string[] sCC, string[] sBCC, string sSubject, bool IsHTML)
{
SmtpClient objSMTPClient = new SmtpClient("localhost");
MailMessage objMessage = new MailMessage();
try
{
MailAddress objFromAddress = new MailAddress(sFromAddress, sFromName);
// From address will be given as a MailAddress Object
objMessage.From = objFromAddress;
// To address collection of MailAddress
for (int i = 1; i <= sToAddress.Length; i++)
{
objMessage.To.Add(sToAddress[i - 1]);
}
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("user@host.com")
if (sCC != null)
{
if (sCC.Length > 0)
{
for (int i = 1; i <= sCC.Length; i++)
{
objMessage.CC.Add(sCC[i - 1]);
}
}
}
if (sBCC != null)
{
if (sBCC.Length > 0)
{
for (int i = 1; i <= sBCC.Length; i++)
{
objMessage.Bcc.Add(sBCC[i - 1]);
}
}
}
// Body can be html or text format
if (IsHTML)
objMessage.IsBodyHtml = true;
objMessage.Subject = sSubject;
objMessage.Body = sMailBody;
// Send SMTP mail
objSMTPClient.Send(objMessage);
}
catch
{
}
}
|
|
|
|
 |
|
 |
Iam using MailMessage and Smtp classes to send email but
iy doesn't work .
I used your code and there is error message after i runs the program .
The mseegae is:
System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040220): The "SendUsing" configuration value is invalid. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) --- End of inner exception stack trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at EMailSample.SendMail.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\testsendemail\sendmail.aspx.cs:line 147
|
|
|
|
 |
|
 |
Thanx Kumar for giving such a good program. My project was at the end point But now it is as smooth as before. Thanx for it. I have just one question. It would be better if you could give the explanation in a different read me file.
|
|
|
|
 |
|
 |
I get this error when an email is sent with attachment from Web page.
If I comment out the line with the attachment, the email is sent fine.
The attachment is a file that is uploaded and then saved on the server.
|
|
|
|
 |
|
 |
Hi
Here you didnt mention which type of file you attach, because if you attach .exe,.dll or some system file's mean your firewall will protect these type of files so you will get invalid mail attachment message.
if you want to attach thest kind of files you can zip the files and attach.
Try like this.....
Thanks
|
|
|
|
 |
|
 |
How to sending a Mail Message with an attachment file that retrieved from mail server?
Thanks.
|
|
|
|
 |
|
 |
What if my SMTP service is runnign on remote machine?
Pls help me.
Thanks
|
|
|
|
 |
|
 |
After calling the SmtpMail.Send (mailMessage), when I try to delete the attachment files I get this:
The process cannot access the file 'C:\Altug\Websites\Medinfo\__sahina_y221xv55cqikh255e2pnqk55\37230006.JPG' because it is being used by another process.
any ideas?
|
|
|
|
 |
|
 |
Just insert line
mailMessage.Dispose();
after SmtpMail.Send
it's work for me
Surat Bunditraksana
|
|
|
|
 |
|
 |
Thank you for the solution to this problem. I had the same error and adding the Dispose() method after sending the message and before deleting the files allowed the files to be deleted.
David Silberman
|
|
|
|
 |
|
 |
Hi,
I have the same problem but not able to delete the file after calling the dispose on finally block.
I have created a temporary file and after sending the mail i have used "objMailMessage.Attachments.Clear()" , "objMailMessage.Attachments.Dispose()" and "objMailMessage.Dispose()" . I have used these code in finally block after sending the mail then i call FIle.Delete(attachmetnfilename) but it throws an exception that "FIle is being used by another process"..
Please help me!
vikram
Vicky
|
|
|
|
 |
|
 |
Me also getting the same error can anyone help us
|
|
|
|
 |
|
 |
Hi,
after sending the mail try this code:
foreach (Attachment a in mail.Attachments)
a.Dispose();
It works for me fine. Deleting the temporary file was possible without errors.
HTH Stephan
modified on Wednesday, June 4, 2008 7:42 AM
|
|
|
|
 |
|
 |
how can i varify using coding that SMTP server is alive.
|
|
|
|
 |
|
 |
hello sir i used ur code to send mail
but mail is not delivering to destination,, it goes to \inetpub\queue and stored there.. also norton is nt scanning any outgoing mail .
i hv checked the setting also
plz help me out
...sam...
Impossible is nothing
|
|
|
|
 |
|
 |
Hi sam
I'm also facing the same problem, mails do not reach to defined destination, instead get stored in queue folder. If you got the solution for this then pl let me know.
Regards
Piyush
|
|
|
|
 |
|
 |
Same problem here...Please someone help!!!
Keep Smiling,
Hemant Jangid
“A professional programmer is an amateur who never quit.”
- Morendil
|
|
|
|
 |
|
 |
For me it worked fine. But when i tried to send large wav file it did not worked instantly. After 5 mintues it was at the destination mail. Please send the error message so we can know about it.
|
|
|
|
 |
|
 |
I used the above code and its very useful for me
|
|
|
|
 |
|
 |
In fact, the code
SmtpMail.SmtpServer.Insert(0,"127.0.0.1");
will not set the SmtpServer property!! It simply does nothing.
But the Mail.Send() works also in case when the SmptServer property is empty or null, the default SMTP server is used than.
|
|
|
|
 |
|
 |
Ya certainly it does't do anything, but some scenario it does't take the SmtpMail.SmtpServer("127.0.0.1")or SmtpMail.SmtpServer("localhost") on that scenario only we need to go this SmtpMail.SmtpServer.Insert(0,"127.0.0.1")
|
|
|
|
 |
|
 |
The following code is a myth and does nothing...
SmtpMail.SmtpServer.Insert(0,"127.0.0.1"); //specifying the real SMTP Mail Server.
Please see my article on this subject...
MYTH: SmtpMail.SmtpServer.Insert(0,"127.0.0.1") Actually Does Something[^]
Matt Stehle - Microsoft Developer Support Team, Messaging and Collaboration
http://blogs.msdn.com/mstehle/
|
|
|
|
 |
|
 |
Hello,
Don't know if guys played a bit with strings but I've noticed something. The Insert Method returns a string.
Here what I was trying to do,
public void SetParameter(string parameterName)
{
parameterName.Insert(0, "@");
}
SetParameter("appid");
The result was, as you guessed it, parameterName == "appid", so the Insert does nothing.
But,
public void SetParameter(string parameterName)
{
parameterName = parameterName.Insert(0, "@");
}
SetParameter("appid");
The result was, parameterName == "@appid", so the Insert does something.
So my gues is,
SmtpMail.SmtpServer = SmtpMail.SmtpServer.Insert(0,"127.0.0.1");
Should Work since SmtpServer is a string. I haven't tested it but the logic is there.... And I do beleive that the Insert method definition is ambiguous....I think they kinda forgot to mention taht it returns the modified string and does not modify the current string.Insert....
my 0.02$
Eric
|
|
|
|
 |
|
 |
I've seen several examples that are similar, but I haven't seen one that handles if you SMTP server requires authentication. Do you know how this would be handled?
Thanks!
|
|
|
|
 |
|
|
 |