C#与Vb.net sendemail [英] C# vs. Vb.net sendemail
问题描述
我有以下用于在多个应用程序中发送电子邮件的C#代码
I have the following C# code for sending an email in several applications
private void MailSend()
{
DateTime Now = System.DateTime.Now;
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient("corimc04");
smtp.Timeout = 5000;
string recipient = recipientCB.SelectedItem.ToString();
try
{
var _with1 = message;
_with1.From = new MailAddress("Non-Stock_MRO_Administrator@gmail.com");
_with1.To.Add(new MailAddress(email));
_with1.Body = "You have a package in receiving ready for pickup from " + supplier + ".\nOn Shelf: " + shelf + ".\nTracking Number: " + trackingNum;
_with1.Subject = "MRO Automated Email for " + recipient;
smtp.Send(message);
message = null;
}
catch (Exception ex)
{
MessageBox.Show("Error Sending emails. " + ex.Message);
}
smtp = null;
return;
}
我还有以下用于在其他应用程序中发送电子邮件的VB代码。
I also have the following VB code for sending an email in other applications.
Sub SendEmail()
Dim smtp As New SmtpClient("corimc04")
smtp.UseDefaultCredentials = True
smtp.Timeout = 5000
Try
Dim message As New MailMessage()
Dim _with1 = message
_with1.From = New MailAddress("Rework_Reporter@gmail.com")
_with1.To.Add(New MailAddress("email"))
_with1.Body = "Rework Status for Rework WIP" & vbLf & data
_with1.Subject = "Rework Report Updates"
smtp.Send(message)
message.Dispose()
Catch ex As Exception
Console.WriteLine("Error Sending emails. " & ex.Message)
End Try
smtp = Nothing
End Sub
今天我的C#代码由于某种原因停止工作,我的C#应用程序都没有发送邮件,但我的VB应用程序仍然发送邮件。我有很多项目使用这个C#代码,不想转换它们。有没有人有任何想法为什么会突然停止?
我尝试过:
我尝试编写一个VB DLL来引用我的C#项目,但无法使其工作。
Today my C# code just stopped working for some reason and none of my C# applications will send mail, but my VB applications still send mail. I have many projects that use this C# code and do not want to have to convert them. Does anyone have any ideas why this would just stop all of a sudden?
What I have tried:
I tried writing a VB DLL to reference in my C# project, but could not get this to work.
推荐答案
不工作?什么不起作用的意思?我对此代码如何工作印象深刻。您甚至不提供电子邮件的凭据以便实际发送它...无论如何......您应该尝试在您的C#代码中输入smtp.UseDefaultCredentials = true ..这是VB.NET代码所做的事情。但是C#代码没有。
Doesn't work ? What "Doesn't work" means ? I am impressed how this code worked. You don't even provide the credentials for your email in order to actually send it... Anyway... you should try to input smtp.UseDefaultCredentials = true at your C# code.. which is something VB.NET code does... but C# code don't.
我收到System.dll错误发送电子邮件中发生的'System.Net.Mail.SmtpException'类型的第一次机会异常。操作已超时。线程'< No Name>'(0x2658)已退出,代码为0(0x0)"
此代码已运行超过一年,但现在正在给出这个例外。
这不是代码的问题。它似乎与SMTP的.NET控件有关。当我在服务器端使用C#应用程序时,应用程序按预期发送电子邮件,但是当我从客户端使用此代码时,似乎这是一个连接问题,尽管我得到的错误是超时错误。
这个线程无法解决。
I receive "A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll Error Sending emails. The operation has timed out.The thread '<No Name>' (0x2658) has exited with code 0 (0x0)"
This code has been working for over a year, but is now giving this exception.
It is not an issue with the code. It seems like it has to do with the .NET controls for SMTP. When I use the C# applications on the server side, the application sends the email as expected, yet when I use this code from the client side, it seems like it's a connection issue, although the error I get is a timeout error.
This will not be solved on this thread.
这篇关于C#与Vb.net sendemail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!