awilderbeast
asked on
c# send mail func trouble
hi all
my first code below works, but my second doesnt do anything can anyone help me fix it?
Thanks
my first code below works, but my second doesnt do anything can anyone help me fix it?
Thanks
############ THIS WORKS ##################
string fromEmail = "mailout@****";//sending email from...
string ToEmail = To.Text;
string body = Editor1.XHTML;
string subject = Subject.Text;
try
{
SmtpClient sMail = new SmtpClient("****");//exchange or smtp server goes here.
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Credentials = new NetworkCredential("mailout@*", "****");
sMail.Send(fromEmail, ToEmail, subject, body);
}
catch (Exception ex)
{
//do something after error if there is one
}
########### THIS DOESNT WORK #################
try
{
MailMessage mail = new MailMessage();
mail.To.Add(To.Text);
mail.IsBodyHtml = true;
mail.Body = Editor1.XHTML;
mail.From = new MailAddress("mailout@****");
mail.Subject = Subject.Text;
SmtpClient sMail = new SmtpClient("*****");
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Credentials = new NetworkCredential("mailout@****", "*****");
sMail.Send(mail);
}
catch(Exception ex)
{
Editor1.Text = Convert.ToString(ex);
}
EditorUpdatePanel.Update();
Can you be more specific? How does it "not work?" Are you getting an exception? Does the mail simply never arrive? Please provide more details.
ASKER
i wish i new
nothing happens at all
no exceptions no mail arrives :S
does the code look ok?
nothing happens at all
no exceptions no mail arrives :S
does the code look ok?
try this:
sMail.UseDefaultCredential s = false;
sMail.UseDefaultCredential
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Credentials = new NetworkCredential("mailout@****", "*****");
sMail.UseDefaultCredentials = false;
sMail.Send(mail);
ASKER
still the same, absolutley nothing is happening :S
the first code still works fine though :S
the first code still works fine though :S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yeah yoru right, its the content of the editor!
its got a table in it, thats breaking it so far, is this a known thing that tables break it?
Thanks
its got a table in it, thats breaking it so far, is this a known thing that tables break it?
Thanks
ASKER
this broke it too
asdasda<span style="color: red; ">sdasdas</span>
Looks like something is up with it:
http://www.velocityreviews.com/forums/t89695-when-mailmessage-bodyformat-mailformat-html-smtpmail-send-throws-exception.html
http://www.velocityreviews.com/forums/t89695-when-mailmessage-bodyformat-mailformat-html-smtpmail-send-throws-exception.html
ASKER
it says
For this to get fixed you can add CDOSYS.dll as refernce to your asp.net application and build the solution and run it should work and will not throw exception.
but where is DSOSYS.dll?
and im creating a web application if that makes differences too
Thanks
For this to get fixed you can add CDOSYS.dll as refernce to your asp.net application and build the solution and run it should work and will not throw exception.
but where is DSOSYS.dll?
and im creating a web application if that makes differences too
Thanks
I don't know. I was just pointing you to a place where others seem to have the same difficulty. It could be this solution presented solves it, but I've not looked into that aspect of it. I think the issue seems somewhat sporadic and it's even possible rebooting yous system might fix it based on another entry in that same forum, I think.
ASKER
i did a wireshark capture to see if the exchange server is reciveing the request and it is
so the email is getting to exchange, i dont know what the responses mean though and why there in purple?
so the email is getting to exchange, i dont know what the responses mean though and why there in purple?
Instead of passing the recipient via the To member, can you try passing it via the constructor like you did in the first example? I seem to recall having some issues with To, but it's been so long I can't remember what they were : \
ASKER
i dont know how to make the two bits of code work together
below is my attempt but it says no, has invalid arguments, as mail is not a string
how can i make it work
heres the wireshark capture of the send to exchange too, forgot to add it before
below is my attempt but it says no, has invalid arguments, as mail is not a string
how can i make it work
heres the wireshark capture of the send to exchange too, forgot to add it before
string StrFrom = "mailout@****.***";
string StrTo = To.Text;
string StrSubject = Subject.Text;
MailMessage mail = new MailMessage();
//mail.To.Add(To.Text);
mail.Body = Editor1.XHTML;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.UTF8;
//mail.Body = "<table><tr><td><span style='color:red;'>TEST</span></td><td>Tester!</td></tr></table>";
//mail.From = new MailAddress("mailout@*****.***");
//mail.Subject = Subject.Text;
OutPut2.Text = mail.Body;
SmtpClient sMail = new SmtpClient("ch-ex.****.****");
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Credentials = new NetworkCredential("mailout@****.****", "****");
sMail.UseDefaultCredentials = false;
sMail.Send(StrFrom, StrTo, StrSubject, mail);
Capture.PNG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that code didnt work at all i didnt even type html just plain text and the other worked in plain text :S
Hmm, I'm not sure how that couldn't work. Can you post your complete code? Are you getting any exceptions, or the code just runs without complaining but no message is delivered?
Also, the entire communication between the sending computer and the mail server should occur on TCP port 25, so you can set a a display filter to "tcp.port == 25" or a capture filter to "tcp port 25" in Wireshark (the capture you have above seems to show regular Windows networking stuff, entirely unrelated to SMTP-based mail transfer) - and you can save the capture to a .cap file and post it, as opposed to a screen shot.
Also, the entire communication between the sending computer and the mail server should occur on TCP port 25, so you can set a a display filter to "tcp.port == 25" or a capture filter to "tcp port 25" in Wireshark (the capture you have above seems to show regular Windows networking stuff, entirely unrelated to SMTP-based mail transfer) - and you can save the capture to a .cap file and post it, as opposed to a screen shot.
ASKER
i just sent an email with both the working and none working code whilst doing a capture with "tcp.port == 25" applied no results returned, are you sure it uses smtp port 25 for sending email via web?
Yes, it would definitely be port 25 unless you have specified something to the contrary in the SmtpClient's constructor, or in your web.config; or if it's a secure connection in which case it'd be 465, I believe.
Here's a capture of an SMTP transaction in Wireshark (rename the the file so the extension is .pcap).
tcp.port.25.example.pcap.txt
Here's a capture of an SMTP transaction in Wireshark (rename the the file so the extension is .pcap).
tcp.port.25.example.pcap.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks