我一直在尝试创建一个小程序来通过smtp.gmail.com发送电子邮件,但它总是提示我"操作已经超时".我知道网上有很多解决方案,但没有一个可行.
try
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress("from@gmail.com");
message.To.Add(new MailAddress("to@gmail.com"));
message.Subject = "Test";
message.Body = "Content";
smtp.Port = 465;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("from@gmail.com", "pwd");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);
}
catch (Exception ex)
{
MessageBox.Show("err: " + ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?
void function() {
try
{
// do something
foreach (item in itemList)
{
try
{
//do something
}
catch (Exception ex)
{
throw new Exception("functionB: " + ex.Message);
}
}
}
catch (Exception ex)
{
LogTransaction(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
嗨,我想将for循环中的异常抛给它的父节点.目前,当for循环中存在异常时,循环将终止.反正有没有修改它,以便抛出异常但循环将继续?
我在连接过程后释放一个 char* 。
但我收到此错误:
free(): 无效的下一个大小 (fast): 0x0000000001b86170
下面是我的代码:
void concat(stringList *list) {
char *res = (char*)malloc(sizeof(char*));
strcpy(res, list->head->string);
list->tmp = list->head->next;
while (list->tmp != NULL) {
strcat(res, ",");
strcat(res, list->tmp->string);
list->tmp = list->tmp->next;
}
printf("%s\n", res);
free(res);
}
Run Code Online (Sandbox Code Playgroud)