小编Joh*_*nny的帖子

如何通过Gmail发送带有C#的电子邮件

尝试通过我的Web服务发送电子邮件时出错.我已尝试启用访问不太安全的应用程序,禁用两步验证并通过Web浏览器登录帐户.SO的解决方案都没有对我有用.我还是得到:

错误:System.Net.Mail.SmtpException:SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.

我该怎么做才能解决这个问题?

namespace EmailService
{
    public class Service1 : IService1
    {    
        public string SendEmail(string inputEmail, string subject, string body)
        {
            string returnString = "";
            try
            {
                MailMessage email = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";

                // set up the Gmail server
                smtp.EnableSsl = true;
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypassword");
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;

                // draft the email
                MailAddress fromAddress = new MailAddress("cse445emailservice@gmail.com");
                email.From = fromAddress;
                email.To.Add(inputEmail);
                email.Subject = body;
                email.Body …
Run Code Online (Sandbox Code Playgroud)

c# gmail smtp smtpclient

13
推荐指数
1
解决办法
5万
查看次数

在给定范围内在Java中生成随机小写字母

我正在尝试编写一个方法,可以采用起始小写字母和结束小写字母,并生成该范围内的随机字母.接下来,将随机字母分配给由用户确定的大小的数组的元素.到目前为止,只要起始字符为"a",我的代码似乎就可以工作.当起始角色不是'a'时,我无法弄清楚如何使它工作.我写了这个完整的程序来尝试解决我的方法:

import java.util.Random;
import java.util.Scanner;
public class Add
{
    public static void main( String[] args )
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter array size: ");
        int arraySize = scan.nextInt();
        char charArray[] = new char[arraySize];

        int fromChar;
        int toChar;
        do
        {
        System.out.print("Enter first character: ");
        String line = scan.next();
        fromChar = line.charAt(0);

        System.out.print("Enter second character: ");
        line = scan.next();
        toChar = line.charAt(0);

        Random generator = new Random();
        for(int i = 0; i < arraySize; i++)
        {
            int randomInt = generator.nextInt(toChar …
Run Code Online (Sandbox Code Playgroud)

java random letters

3
推荐指数
1
解决办法
3915
查看次数

为什么我的C程序在执行字符的tolower转换期间打印"(null)"?

我写了这个程序,试图更好地理解C. 它有效,但由于某种原因,在正确的输出之前打印(null).我的代码:

/* This program will take a string input input from the keyboard, convert the
string into all lowercase characters, then print the result.*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    int i = 0;
    /* A nice long string */
    char str[1024];                               
    char c;
    printf("Please enter a string you wish to convert to all lowercase: ");

    /* notice stdin being passed in for keyboard input*/
    fgets(str, 1024, stdin);  //beware: fgets will add a '\n' character if …
Run Code Online (Sandbox Code Playgroud)

c null fgets tolower

2
推荐指数
1
解决办法
1793
查看次数

如何在XML中为Android Google MapFragment制作set lite模式?

Android的文档指出,最简单的方法来创建一个MapFragment在XML是像这样:

<fragment
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

如果以这种方式创建MapFragment,如何将lite模式设置为true

xml android google-maps

2
推荐指数
2
解决办法
5585
查看次数

对于LinkedList类型,方法addElement是未定义的

我正在进行一项任务,我正在尝试向LinkedList添加一个元素.第一个代码块是给定的,不应该更改.第二个块是根据教授给我们的UML编写的,位于另一个类中.

import java.io.*;
import java.util.LinkedList;

public class Assignment10
{
   public static void main(String[] args)
   {
       char input1;
       String inputInfo = new String();
       int operation2;
       String line = new String();

       //create a linked list to be used in this method.
       LinkedList list1 = new LinkedList();

       try
        {
         // print out the menu
         printMenu();

         // create a BufferedReader object to read input from a keyboard
         InputStreamReader isr = new InputStreamReader (System.in);
         BufferedReader stdin = new BufferedReader (isr);

         do
          {
           System.out.print("What action would …
Run Code Online (Sandbox Code Playgroud)

java eclipse undefined

0
推荐指数
1
解决办法
2422
查看次数

为什么我的变量在我的C程序中的递归调用中改变了值?

我写了一个程序来查找数组中最大的数字.问题是,每次find_largest递归调用函数时,largest变量似乎都会被内存中其他地方的垃圾填满.我已经使用调试器逐步完成它,它似乎工作正常,直到递归调用.largest如果适用,数组和更新的指针显示预期值.

/*This program will find the largest integer in an array. It was written to practice
using recursion.*/

#include <stdio.h>
void find_largest(int *a, int n);
int main() {
    int a[] = {10, 27, 101, -8, 16, 93}; 
    int n = 6, i = 0;
    printf("Current array: ");
    while(i < n) {//print array
        printf("%d ", a[i]);
        i++;
    }
    find_largest(a, n);
    return 0;
}//end main

//This function will start at the last element, and then step …
Run Code Online (Sandbox Code Playgroud)

c memory variables recursion

0
推荐指数
1
解决办法
2903
查看次数

标签 统计

c ×2

java ×2

android ×1

c# ×1

eclipse ×1

fgets ×1

gmail ×1

google-maps ×1

letters ×1

memory ×1

null ×1

random ×1

recursion ×1

smtp ×1

smtpclient ×1

tolower ×1

undefined ×1

variables ×1

xml ×1